0

I am trying to use electron-packager to package an electron app. When packaging my app I want to ignore the entire contents of certain folders. Using the --ignore flag you can pass a regular expression to electron-packager to tell it to ignore matches.

My folder structure looks like

app
|--build
|--node_modules
|--src
index.html
main.js
package.json

Using the method from the accepted answer of this question I prepended my expression with ^ to restrict the pattern to the root level.

let execArgs = `npx electron-packager ./ "${productName}"`
    + ` --platform=win32`
    + ` --out=${outPath}`
    + ' --ignore=^/build';
execSync(execArgs);

However, electron-packager appears to still be ignoring more than just the specific folders. If I try running the packaged app I get the error Error: Cannot find module '../helpers/buildURL'. The full relative path of this file is ./node_modules/axios/lib/helpers/buildURL.js.

If I comment out the line ignoring the build folder, I no longer get the error above.

// + ' --ignore=^/build'

How can I make electron-packager ignore specific folders and their contents from the root level?

No stupid questions
  • 425
  • 1
  • 11
  • 31

2 Answers2

0

Looks like all I had to do was surround my argument in quotes.

+ ' --ignore="^/build"';

I'm not sure why this made a difference, since my argument does not include any spaces, but when I surrounded it in quotes the expression ignored only the correct files.

No stupid questions
  • 425
  • 1
  • 11
  • 31
0

I always use this script to ignore files when I package an electron app

script{"electron-build":"electron-packager . MYAPP --ignore build/* }

Sidali
  • 1
  • 1
  • 4
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 30 '22 at 03:56