当uglifyjs-webpack-plugin工作时,webpack.optimize.UglifyJSPlugin不起作用

时间:2018-02-15 11:34:12

标签: javascript webpack uglifyjs

我有2个文件open( r"C:\testGupixwin\BX-N-H.HED", "r" ) #rawstring # or open( "C:\\testGupixwin\\BX-N-H.HED", "r" ) #escaping the '\' with '\' & app.js

它包含以下代码 -

app.js

math.js

math.js

import { sum } from "./math";

console.log("");

console.log(sum(2, 3));

webpack.config.js

export const sum = (a, b) => a + b;
export const multiply = (m, n) => m * n;

完整代码位于https://github.com/deadcoder0904/webpack-treeshake

问题是const path = require("path"); const webpack = require("webpack"); const UglifyJsPlugin = require("uglifyjs-webpack-plugin"); const config = { entry: "./app.js", output: { path: path.resolve(__dirname, "dist"), filename: "bundle.js" }, plugins: [ new UglifyJsPlugin() // new webpack.optimize.UglifyJsPlugin() doesn't work ] }; module.exports = config; 有效但UglifyJsPlugin不起作用

我的webpack.optimize.UglifyJsPlugin()版本是v3.11.0

1 个答案:

答案 0 :(得分:0)

回答我自己的问题。谢谢@str帮忙。

我使用的是不同版本的Uglify JS,不确定是不是问题。

所以我尝试安装现在处于测试阶段的webpack版本4,因此我必须安装groupBy(lit(1))。此外,webpack@next现在是它自己的包,所以我也必须安装它。早些时候,它与webpack-cli本身捆绑在一起。

安装webpack& webpack@next,我将webpack-cli更改为 -

webpack.config,JS

webpack.config,js

并运行以下内容以使用TreeShaking生成包

const path = require("path"); const webpack = require("webpack"); const config = { entry: "./app.js", output: { path: path.resolve(__dirname, "dist"), filename: "bundle.js" } }; module.exports = config;

完整代码位于https://github.com/deadcoder0904/webpack-treeshake

查看我对TreeShake with Lodash执行所有树木扫描的其他答案