我有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
它包含以下代码 -
math.js
import { sum } from "./math";
console.log("");
console.log(sum(2, 3));
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
答案 0 :(得分:0)
回答我自己的问题。谢谢@str帮忙。
我使用的是不同版本的Uglify JS,不确定是不是问题。
所以我尝试安装现在处于测试阶段的webpack版本4,因此我必须安装groupBy(lit(1))
。此外,webpack@next
现在是它自己的包,所以我也必须安装它。早些时候,它与webpack-cli
本身捆绑在一起。
安装webpack
& webpack@next
,我将webpack-cli
更改为 -
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执行所有树木扫描的其他答案