grunt-browserify icon indicating copy to clipboard operation
grunt-browserify copied to clipboard

Exclude is not working

Open tandrewnichols opened this issue 8 years ago • 6 comments

I know there have been other issues to this effect that have been resolved, so it's possible I'm doing this wrong. I want to set up two different bundles, one that includes lodash and one that is a standalone for people who have lodash included in their client scripts already. It looks like the right option is exclude (although I've also tried ignore), but I can't get grunt-browserify to leave out lodash. Here's my configuration for the two different bundles:

grunt.initConfig({
  browserify: {
    dist: {
      files: {
        'dist/feature-toggle-lib.js': 'dist/request-decoration.js'
      },
      options: {
        browserifyOptions: {
          standalone: 'FtoggleRequestDecoration'
        }
      }
    },
    standalone: {
      files: {
        'dist/feature-toggle-lib-standalone.js': 'dist/request-decoration.js'
      },
      options: {
        exclude: 'lodash',
        browserifyOptions: {
          standalone: 'FtoggleRequestDecoration'
        }
      }
    }
  }
});

As I mentioned, I've also tried replacing exclude with ignore and I've tried putting both inside browserifyOptions, and in all cases, lodash is still included in the build. Incidentally, when I do this directly with browserify, it works fine: browserify dist/request-decoration.js --exclude lodash --standalone FtoggleRequestDecoration > dist/feature-toggle-lib-standalone.js.

I know you'll ask what version I'm using; I updated to the most recent (^4.0.0) when this wasn't working, and that did not fix it.

tandrewnichols avatar Aug 18 '15 13:08 tandrewnichols

I just had the same problem and figured it out. You can get exclude to work by specifying the excludes as an Array like so:

options: {
    exclude: ['nw.gui']
}

RaederDev avatar Oct 24 '15 16:10 RaederDev

Interesting. I'll give that a try. Thanks!

tandrewnichols avatar Oct 24 '15 17:10 tandrewnichols

Yep, a lot of options require to be an array. We should probably also allow a single entry and convert it to an array when needed.

tleunen avatar Oct 24 '15 18:10 tleunen

I'm running grunt-browserify v4.0.1, grunt v0.4.5 and browserify v12.0.1 and have this problem too... I have a directory with all my source, which I browserify like this:

 14         browserify: {
 15             libs: {
 16                 src: ['src/*.js'],
 17                 dest: 'dist/libs.js'
 18             },  

and everything is fine, except that when I drop an index.js in the directory, which I need to exclude from browserification, I can't get the module to exclude it. I know it's not being excluded because the presence of that file generates the error:

Running "browserify:libs" (browserify) task

Error: Cannot find module './package.json' from '/Users/ekkis/Development/xxx/src' Warning: Error running grunt-browserify. Use --force to continue.

here's what I currently have:

 14         browserify: {
 15             libs: {
 16                 src: ['src/*.js'],
 17                 dest: 'dist/libs.js',
 18                 options: {
 19                     exclude: ['index.js']
 20                 }
 21             },  

but like others, I've tried

ignore: `index.js'
exclude: 'index'
exclude: ['index'] 
exclude: 'index.js'
exclude: ['index.js'] 
exclude: 'src/index.js'
exclude: ['src/index.js'] 

all which fail in the same manner. curiously, the last attempt generates a different error:

Fatal error: cb is not a function

what am I doing wrong?

ekkis avatar Feb 12 '16 02:02 ekkis

I can confirm, that this issue also occurs with ignore. Also tired several ways, like @ekkis , nothing helped.

0815fox avatar Mar 09 '16 10:03 0815fox

My fix above was wrong, it is a side effect. I just came across https://github.com/substack/node-browserify/issues/1433 and now tried a relative path:

ignore: ['./build/**/XYZ.js']

This may also work with exclude?

0815fox avatar Mar 09 '16 11:03 0815fox