question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use ignore files when packaging

See original GitHub issue

electron-builder: 3.16.0

I have a project setup using the two package.json structure. Everything works fine now, but I need to dynamically ignore files from the package. To do this, I am switching from the CLI to the API.

My current build command is:

build --arch ia32 --platform win32 -d

I have changed it to the following script:

'use strict';

const builder = require('electron-builder');

const opts = {
    platform: [builder.Platform.WINDOWS],
    arch: 'ia32',
    dist: true,
    devMetadata: {
        build: {
            win: {
                ignore: function (file) {
                    // TODO: add logic here
                    console.log(file);
                    return false;
                }
            }
        }
    }
};

builder.build(opts)
    .catch((err) => {
        console.log(err);
        process.exit(1);
    });

However, the ignore field is not being read; all files are packaged and all the filenames are not being printed. Any idea on why this is?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

40reactions
singhshashicommented, Feb 15, 2018

Just leaving a comment here for anyone else who lands up searching for how to ignore files. You do that using the files configuration https://www.electron.build/configuration/contents#files.

e.g.

"build": {
    "appId": "com.gettrici",
    "productName": "Trici",
    "mac": {
      "category": "public.app-category.developer-tools",
      "icon": "resources/images/trici_icon.icns",
      "target": "zip",
      "asar": false,
      "compression": "store",
      "files":["!builds/*","!patches/*","!packages/*"]
    }
  },

It was not immediately clear to me from the documentation how to ignore files.

1reaction
farfromrefugcommented, May 31, 2016

Ok so i dropped by app size by around 80% just using the ignore function on the node_modules directory:

function(filePath) {
                    if (/node_modules/.test(filePath)) {
                        if (/\/(obj|test.*?|spec.*?|htdocs|demo|dist|example.*?|sample.*?)[\/$]/i.test(filePath)) {
                            return true;
                        }
                        if (/^(\..*|.*\.(sln|pdb|exp|lib|map|md|sh|gypi|gyp|h|cpp|xml|yml|html)|vcxproj.*|LICENSE|README|CONTRIBUTORS|vagrant|Dockerfile|Makefile)$/i.test(path.basename(filePath))) {
                            return true;
                        }
                    }

                    // console.log(filePath);
                };

Could really use glob for this. keep in mind that some should not be ignore in some app cases (html, xml,…)

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to ignore files from your npm package | Zell Liew
First, npm will check your repository for a .gitignore file. If there is a .gitignore file, npm will ignore files according to what's...
Read more >
What Really Gets Packaged?. Including and excluding files in ...
I'd recommend using the files section in the package.json file over ... In fact, the .npmignore file and the .gitignore file are ignored....
Read more >
How can I exclude files in my .gitignore when packaging a ...
I have the package installed globally, in my python's site-packages ... Then you can use those files to package the egg however you...
Read more >
.gitignore file - ignoring files in Git | Atlassian Git Tutorial
Git ignore patterns are used to exclude certain files in your working directory from your Git history. They can be local, global, or...
Read more >
Ignore files when building debian package
It is very unusual to use low level commands like dpkg-deb to build debian packages - this looks like a XY-problem. Usually, you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found