【发布时间】:2020-01-09 18:39:54
【问题描述】:
我正在创建一个 React JS 应用程序。我已经安装了 terser-webpack-plugin 来尝试压缩我的代码以及删除 console.log() 语句。但是,它似乎不起作用。
我已经安装了 terser-webpack-plugin 如下:
npm install terser-webpack-plugin --save-dev
我的 webpack.config.js 文件如下所示:
const HtmlWebPackPlugin = require("html-webpack-plugin");
const CopyPlugin = require('copy-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
module.exports = {
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
plugins: [
"@babel/plugin-syntax-dynamic-import"
]
}
}
},
{
test: /\.html$/,
use: [
{
loader: "html-loader"
}
]
}
]
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
extractComments: 'all',
compress: {
drop_console: true
},
}
})
],
},
devtool: 'eval-source-map',
plugins: [
new HtmlWebPackPlugin({
template: "./src/index.html",
filename: "./index.html"
}),
new CopyPlugin([
{ from: 'src/css', to: 'css' }
])
]
};
但是,当我运行 npm run build 或 npm run dev 时,它似乎对最终文件大小没有任何影响,并且 cmets 仍然存在。我做错了什么?
作为旁注,我想知道如何确保这仅适用于构建并且不会删除 dev 上的 cmets。
【问题讨论】:
标签: javascript reactjs webpack plugins