I am running react-app-rewired and Webpack 4.29.3 and am trying to load a config with optimization in it.
Here is my config-override.js:
const TerserPlugin = require('terser-webpack-plugin');
module.exports = function override(config, env) {
config.optimization = {
minimizer: [new TerserPlugin({})],
};
return config;
}
But it gives the following error:
Creating an optimized production build...
Failed to compile.
Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
- configuration has an unknown property 'optimization'. These properties are valid:
object { amd?, bail?, cache?, context?, dependencies?, devServer?, devtool?, entry, externals?, loader?, module?, name?, node?, output?, parallelism?, performance?, plugins?, profile?, recordsInputPath?, recordsOutputPath?, recordsPath?, resolve?, resolveLoader?, stats?, target?, watch?, watchOptions? }
For typos: please correct them.
For loader options: webpack 2 no longer allows custom properties in configuration.
Loaders should be updated to allow passing options via loader options in module.rules.
Until loaders are updated one can use the LoaderOptionsPlugin to pass these options to the loader:
plugins: [
new webpack.LoaderOptionsPlugin({
// test: /\.xxx$/, // may apply this only for some modules
options: {
optimization: ...
}
})
]
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Now according to the documentation, config.optimization should just work fine. I have removed node-modules cleared the lock files and reinstalled.