-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.dll.js
105 lines (101 loc) · 2.18 KB
/
webpack.dll.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
const fs = require("fs");
const path = require("path");
const dir = path.join.bind(path, __dirname);
const isProd = process.env.NODE_ENV === "production";
const fm = (list, file) => {
const txt = list.map(
v => fs.readFileSync(dir(v), "utf-8")
).join("\n") || "";
const target = dir("build");
fs.existsSync(target) || fs.mkdirSync(target);
fs.writeFileSync(dir("build", file), txt, "utf-8");
};
const jsList = [
"jquery/dist/jquery",
"jquery-ui-dist/jquery-ui",
].map(v => isProd
? `node_modules/${v}.min.js`
: `node_modules/${v}.js`
);
fm(jsList, "jquery.dll.js");
const webpack = require("webpack");
const UglifyJSPlugin = require("uglifyjs-webpack-plugin");
const dllConfig = {
entry: {
shim: [
"console-polyfill",
"babel-polyfill",
"raf/polyfill",
"media-match",
],
public: [
"pace",
"axios",
"moment",
"numeral",
"signals",
"js-cookie",
"nprogress",
"pubsub-js",
"moment/locale/zh-cn",
],
vendor: [
"react",
"react-dom",
"redux",
"redux-undo",
"react-redux",
"react-router-dom",
],
},
output: {
path: dir("build"),
filename: "[name].dll.js",
library: "[name]_[chunkhash:5]",
// library 与 DllPlugin 中的 name 一致
},
plugins: [
new webpack.DefinePlugin({
"process.env": {
"NODE_ENV": JSON.stringify(
isProd ? "production" : "development"
),
},
}),
/*new webpack.ContextReplacementPlugin(
/moment[\\/]locale$/i,
/^\.\/zh-cn$/i,
),*/
new webpack.IgnorePlugin(/^\.\/locale$/i, /moment$/i),
new webpack.DllPlugin({
context: __dirname,
name: "[name]_[chunkhash:5]",
path: dir("build", "[name].manifest.json"),
}),
],
resolve: {
alias: {
/*api: dir("src/api"),
components: dir("src/components"),
containers: dir("src/containers"),
constants: dir("src/constants"),
reducers: dir("src/reducers"),
actions: dir("src/actions"),
routes: dir("src/routes"),
styles: dir("src/styles"),
views: dir("src/views"),
utils: dir("src/utils"),
"@": dir("src"),*/
},
extensions: [".js", ".jsx", ".json"],
},
performance: {
hints: false,
},
};
if (isProd) {
dllConfig.plugins.push(new UglifyJSPlugin({
sourceMap: false,
}));
}
module.exports = dllConfig;