Yes, there is a way to configure Webpack to prevent the creation of the bundle.LICENSE.txt
files in the build output.
Even though Webpack 5 includes the terser plugin out of the box, if you wish to customise it, you will still need to install it as a dependency, and then set the extractComments: false
in the optimization settings, to stop the license text files being generated.
Step 1 - Install the terser plugin as a dev dependency
npm install terser-webpack-plugin --save-dev
Step 2 - Import the plugin into your webpack.config.js
const TerserPlugin = require("terser-webpack-plugin");
Step 3 - Add the optimization key and value
const TerserPlugin = require("terser-webpack-plugin");
// ...
module.exports = () => {
return {
entry: './src/index.tsx',
module: {
// ...
},
resolve: {
// ...
},
output: {
// ...
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: false,
}),
],
},
plugins: [
// ...
],
};
};
Once you have done this, the license text files should no longer appear in the build output directory.
You can take a look at these docs for more information: https://webpack.js.org/plugins/terser-webpack-plugin/#extractcomments
package.json
. When I added it back, it didn't seem to generate this license file anymore for.js
files but not for.tsx
files that are compiled into js