#ElectronForge TypeScript WebPack & external modules!

84 messages · Page 1 of 1 (latest)

jade token
#

I've got a project that is using ElectronForge v6.0.3 with TypeScript and WebPack, I'm loading a native npm, module leveldb-zlib I've got it to work when running electron-forge start but when I run electron-forge make it throws the following error on windows 10 x64 any help would be amazing!

frail lodge
jade token
#

@frail lodge take at look in the electron-forge channel, that is how i got it to work, I'm curious if you did the same as me? 🙂

frail lodge
jade token
#

@frail lodge how slow is your builds? mine are taking a long ass time lol

frail lodge
jade token
#

hmm i guess we could have a whitelist?

#

maybe read the webpack config for externals

#

then add those only

#

I'll make that change and report back xD

acoustic blaze
jade token
#

ok I'll give that ago

#

@acoustic blaze ok wow that was much faster

acoustic blaze
#

disclaimer: I'm not sure if the workaround you found is the right way to solve your problem, but assuming it is, installing dependencies in production mode is the way to go

jade token
#

yeah I'm very new to electron so any advice is much appreciated

acoustic blaze
#

also, try adding asar: true to the packageConfig object in your forge.config, it should speed things up a bit more

jade token
#

ok!

#

asar seems to break it

#

prevents finding the module

acoustic blaze
#

what about (assuming the module is installed in node_modules/leveldb-zlib):

  packagerConfig: {
    asar: {
      unpackDir: 'node_modules/leveldb-zlib/**/*',
    },
  },
jade token
#

i'll give that a go

#

this is the example im messing with btw

jade token
#

I don't really understand what exactly that is doing

acoustic blaze
# jade token I don't really understand what exactly that is doing

the asar option packs your files/dependencies into a single .asar file, which is a format Electron can read. asar: true packs everything, including native modules, while asar: { unpackDir: 'node_modules/leveldb-zlib/**/*' } skips that folder you specified.

if you look at the folder structure in your packaged app, you'll see an app.asar file and a app.asar.unpacked folder inside the resources folder. when you import leveldb-zlib, it will be read from app.asar.unpacked folder, while any other dependencies/project files will be read from the app.asar file

jade token
#

ah alright!

#

I'm just trying to get this to work for my actual app lol it works just fine for the demo app, but the actual compiles but wont load, does not error or anything but it just does not open the program

acoustic blaze
jade token
#

yeah

#

running it from PS

#

I'm surprised it is quite a process to get stuff like this working

acoustic blaze
jade token
#

o sec

acoustic blaze
jade token
#

oof

#

failing to load an image

#

^me

acoustic blaze
#

yeah, it's usually stuff like that or a missing comma

jade token
#

yeah I'm going to blame it on no sleep, I work at a hospital over night and wrote code by day lol

#

const tray = new Tray("images/cole_favicon.ico");

#

this would be the cause I imagine

#

works for dev tho lol

acoustic blaze
acoustic blaze
jade token
#

I'll try that

#

if you ever need kubernetes help i'm your guy 😅

#

just got it built, didn't seem to work

#

hmm

jade token
#

fianlly got it to work

#

but the styles are not correct

#

always something...

acoustic blaze
#

how did you fix the icon?

jade token
#

I didn't yet haha still working on that but what i thought was going to fix it at least let it load

#
  const iconPath = path.join(__dirname, 'build/images/cole-favicon.ico');
  const tray = new Tray(nativeImage.createFromPath(iconPath));
acoustic blaze
#
const tray = new Tray(app.isPackaged ? path.join(__dirname, '../images/cole_favicon.ico') : 'images/cole_favicon.ico')

then install https://www.npmjs.com/package/copy-webpack-plugin and add this to your webpack.main.config.ts:

  plugins: [
    new CopyPlugin({
      patterns: [
        {
          from: path.resolve(__dirname, 'images'),
          to: path.join(__dirname, '/.webpack/images'),
        }
      ],
    }),
  ]
jade token
#

@acoustic blaze I got the icon working!

#

webpack.plugins.ts

import type IForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
// eslint-disable-next-line import/default
import CopyPlugin from "copy-webpack-plugin";
import * as path from "path";


// eslint-disable-next-line @typescript-eslint/no-var-requires
const ForkTsCheckerWebpackPlugin: typeof IForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');

export const plugins = [
  new ForkTsCheckerWebpackPlugin({
    logger: 'webpack-infrastructure',
  }),
  new CopyPlugin({
    patterns: [
      {
        from: path.join(__dirname, "images"),
        to: path.resolve(__dirname, ".webpack", "main/images")
      }
    ]
  })
];
  const iconPath = path.join(__dirname, 'images/cole_favicon.ico');
  const tray = new Tray(iconPath);
#

time to figure out why tailwind styles are not being applied haha

acoustic blaze
#

good luck with that, tailwind is not my thing

jade token
#

all good, i really appreciate your help and explanations!

acoustic blaze
#

glad to help 😀

jade token
#

im thinking my styles.css is not being packaged

#

I don't see any css files in the .webpack folder

jade token
#

nevermind, it is working correctly the css just looks different in prod? strange

acoustic blaze
#

are you using something called postcss-flexbugs-fixes by any chance?

#

I worked on a tailwind project a while ago and this guy ruined my styles in production as well

jade token
#

it's all working now 🙂 i just needed to hard reset the css rules

jade token
#

@acoustic blaze

#

this is the final result 😄 all compiled and working

#

I've got a branding server, and the icon will automatically change based on the season

#

or if it's the employee's birthday

acoustic blaze
#

looking good!

#

is it released yet?

jade token
#

not yet, I'm just deploying a private update server

#

using nucleus

#

I'm planning on writing my own release server in the future