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.

Override webpack optimization

See original GitHub issue

Hi, I need some help trying to override the settings in TerserPlugin to disable mangling. Is this supported currently? I’ve tried setting up something like this but it doesn’t seem to take effect… Not 100% sure I’m doing it correctly.

webpack: {
    optimization: {
      minimizer: [
        new TerserPlugin({
          terserOptions: {
            mangle: false
...

The configuration I’m trying to modify is here https://github.com/facebook/create-react-app/blob/49e258b4a6d04fb7e3542d7a060c6dcad4093564/packages/react-scripts/config/webpack.config.js#L182

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

5reactions
patricklafrancecommented, Dec 4, 2018

Hi @carlosfunk

Yes it is supported but you have to use

webpack: {
    configure: {
        optimization: { .... }
    }
}

or

webpack: {
    configure: webpackConfig => {
          webpackConfig.optimization.minimizer = ....

          return webpackConfig;
    }
}
3reactions
liorfrenkelcommented, Jan 13, 2020

hey guys, in order to change the terser config, use the plugins section of craco:

// craco.config.js
module.exports = {
  plugins: [
    {
      plugin: {
        overrideWebpackConfig: ({
          webpackConfig,
        }) => {
          const minimizerIndex = webpackConfig.optimization.minimizer.findIndex(item => item.options.terserOptions);

          // do not mangle problematic modules of bitcoinjs-lib
          webpackConfig.optimization.minimizer[minimizerIndex].options.terserOptions.mangle = {
            ...webpackConfig.optimization.minimizer[minimizerIndex].options.terserOptions.mangle,
            reserved: ['BigInteger', 'ECPair', 'Point']
          };

          return webpackConfig;
        },
      },
    },
  ],
};

here I find the index of the terser plugin by searching for terserOptions
then I use that object to add/override the reserved option.
I hope that helps!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Override webpack optimization · Issue #44 · dilanx/craco
Hi, I need some help trying to override the settings in TerserPlugin to disable mangling. Is this supported currently? ... Override webpack optimization...
Read more >
Optimization - webpack
Allows you to override the default minimizer by providing a different one or more customized TerserPlugin instances. ... const TerserPlugin = require('terser- ...
Read more >
Webpack build task overriding optimizations - Stack Overflow
Problem: The production build task is minifying files but then overriding those with unminified files. · Context: I'm using an environment ...
Read more >
Overriding the Create-React-App Webpack Configuration ...
json , I created a build. js file to override the Webpack build: // in ./build. js const rewire = require('rewire'); const defaults...
Read more >
An in-depth guide to performance optimization with webpack
A good understanding of webpack's underlying principles can vastly improve your bundle size, application performance, and user experience.
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