Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't remove default plugins via webpack-configurator #3673

Closed
vanbroup opened this issue Jan 24, 2018 · 5 comments
Closed

Can't remove default plugins via webpack-configurator #3673

vanbroup opened this issue Jan 24, 2018 · 5 comments

Comments

@vanbroup
Copy link

I'm trying to replace the default UglifyJsPlugin via config.removePlugin as specified in the webpack-configurator documentation:

    config.removePlugin('uglify');
    config.removePlugin('uglify-js');
    config.removePlugin('UglifyJsPlugin');

Unfortunately none of the above seem to work. I think because the UglifyJsPlugin is not loaded via the config.plugin system in webpack.config.js.

I found an ugly workaround by updating the configuration and excluding all files:

const webpack = require('webpack')

exports.modifyWebpackConfig = ({ config, stage }) => {
  if (stage === 'build-javascript') {
    // disbale the default uglify plugin
    const uglifyJsPluginInstace = config._config.plugins.find(
      plugin => plugin instanceof webpack.optimize.UglifyJsPlugin
    )
    if (uglifyJsPluginInstace) {
      uglifyJsPluginInstace.options = {
        exclude: /.*/
      }
    }

    // use the es6 compatible uglify plugin
    const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
    config.plugin('uglifyjs-webpack-plugin', () => new UglifyJsPlugin());
  }
  return config
}
@calcsam
Copy link
Contributor

calcsam commented Jan 25, 2018

Yes, we hard-code uglify here:

new webpack.optimize.UglifyJsPlugin({

What's the use case you have for removing it?

@KyleAMathews
Copy link
Contributor

A PR making Uglify overridable would be great 👍

@vanbroup
Copy link
Author

@calcsam the hardcoded version of UglifyJsPlugin breaks on many dependencies such as punycode and moment. The alternative uglifyjs-webpack-plugin is using UglifyJS v3 (uglify-es).

@KyleAMathews I would love to create some pull requests, unfortunately, at this moment all my time is needed to optimize the build, which is still including 70% of not used bytes. (It would help if included stylesheets would only cover the first render, everything else (for other pages) can be loaded dynamically. In our case, we only need 90% of the styles on a management page when a user logged-in, but currently, they are included in every view. PurifyCSS doesn't help in this case)

@ghost
Copy link

ghost commented Jan 26, 2018

@vanbroup I'm using CSS-in-JS, I think it's builtin with Gatsby? It still hurts my eyes sometimes because I always cared to keep styles separate. But Gatsby changed the game. It makes now sense to keep it in your Templates, so only the styles that's really used get loaded. Since it's not inline css you don't need to worry about performance. I think I'll remember that's the preferred way Kyle use, so it can't be wrong 👍

@KyleAMathews
Copy link
Contributor

Due to the high volume of issues, we're closing out older ones without recent activity. Please open a new issue if you need help!

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

No branches or pull requests

3 participants