Skip to content
This repository has been archived by the owner on Dec 5, 2019. It is now read-only.

Expose chunk to options.<test|include|exclude> #21

Closed
japgolly opened this issue Mar 23, 2017 · 4 comments · Fixed by #382
Closed

Expose chunk to options.<test|include|exclude> #21

japgolly opened this issue Mar 23, 2017 · 4 comments · Fixed by #382

Comments

@japgolly
Copy link

The test, include and exclude options only inspect the output filename, which has no value when the names are like [hash].[ext]. It would be very helpful to expose the associated chunk info as well.

@michael-ciniawsky michael-ciniawsky changed the title Expose chunk to test/include/exclude feat: expose chunk to options.<test|include|exclude> Jul 4, 2017
@hulkish
Copy link
Contributor

hulkish commented Jul 12, 2017

@japgolly How about this for usage:

new UglifyJsPlugin ({ 
  // same as current behavior, would convert old syntax to this for legacy support.
  assets: {
    test: /uglify-me-with-ecma-5.js/,
    exclude: path.resolve(__dirname, '../src/dont-uglify-me-bro'),
    options: {// override the plugin uglifyOptions per match!
      ecma: 5
    }
  },
  modules: {
    include: /uglify-me-with-ecma-8.js/,
    options: {
      ecma: 8
    }
    // also accepts test/exclude 
  },
  uglifyOptions: {
    ecma: 7
  }
});

and/or:

new UglifyJsPlugin ({ 
  assets: [
    {
      test: /uglify-me-with-ecma-5.js$/,
      exclude: path.resolve(__dirname, '../src/dont-uglify-me-bro'),
      options: { ecma: 5 }
    },
    {
      test: /uglify-me-with-ecma-5.js$/,
      exclude: path.resolve(__dirname, '../src/dont-uglify-me-bro'),
      options: { ecma: 5 }
    },
  ]
  modules: [
    {
      include: /uglify-me-with-ecma-8.js$/,
      options: { ecma: 8 }
    },
    {
      include: /uglify-me-with-ecma-8.js$/,
      options: { ecma: 8 }
    },
  ],
  uglifyOptions: {
    ecma: 7
  }
});

and/or:

new UglifyJsPlugin ({ 
  modules(module) (
    if (module.resource.indexOf('uglify-me-bro.js') > -1) {
      return { ecma: 8 }; // can return boolean or object
    }
    return true;
  ),
  assets(file) (
    return file.indexOf('plssss-uglify-me.js') > -1;
  ),
  uglifyOptions: {
    ecma: 7
  }
});

and/or:

new UglifyJsPlugin ({ 
  assets: /plssss-uglify-me.js$/,
  uglifyOptions: {
    ecma: 7
  }
});

I think this offers the finest grain of control.

@michael-ciniawsky michael-ciniawsky changed the title feat: expose chunk to options.<test|include|exclude> Expose chunk to options.<test|include|exclude> Nov 10, 2017
@FranckFreiburger
Copy link

FranckFreiburger commented Jan 23, 2018

I have created a loader for javascript-obfuscator, and I would like to avoid uglifyjs-webpack-plugin to process resources that pass through that loader (because obfuscated code must not be uglified).

I would like to use something like:

  modules(module) (
    if ( module.loaders.find(loader => .... 'javascript-obfuscator-loader' ....) !== null ) {
      return false
    }
    return true;
  ),

@Friksel
Copy link

Friksel commented Dec 9, 2018

+1
A way to exclude libs from uglifying/mangling would be very welcome!

@alexander-akait
Copy link
Member

Will be shipped in near future

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants