我的webpack.config.js中有以下包
const CopyWebpackPlugin = require("copy-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const UglifyJS = require("uglify-es");这是我的配置中使用这些包的一部分:
optimization: {
minimizer: [new TerserPlugin()],
},
plugins: {
new CopyWebpackPlugin([
{
from: "./node_modules/whatwg-fetch/dist/fetch.umd.js",
to: "./js/polyfills/whatwg-fetch.js",
transform: content => UglifyJS.minify(content.toString()).code,
},
]),
}因此,我使用terser最小化了我的常见捆绑包,并通过uglify为copy-webpack插件复制的源代码提供了精简。我想去掉uglify,用terser代替它,因为它们都被用来缩小。有可能吗?terser插件可以在optimization配置节之外使用吗?或者我可以以某种方式告诉他最小化我手动复制的源代码?
发布于 2019-04-24 07:11:19
事实证明,解决方案很简单。由于terser-webpack-plugin包含terser,因此可以独立使用。
const CopyWebpackPlugin = require("copy-webpack-plugin");
const Terser = require("terser");并且不需要将terser添加到依赖列表中!然后我们可以随时显式地使用它:
plugins: {
new CopyWebpackPlugin([
{
from: "./node_modules/whatwg-fetch/dist/fetch.umd.js",
to: "./js/polyfills/whatwg-fetch.js",
transform: content => Terser.minify(content.toString()).code,
},
]),
}https://stackoverflow.com/questions/55801667
复制相似问题