Skip to content

Commit 3401b51

Browse files
committed
add webpack-multiple-commons-chunks
1 parent 63a9bd1 commit 3401b51

File tree

19 files changed

+108
-0
lines changed

19 files changed

+108
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"presets": ["es2015"],
3+
"plugins": ["add-module-exports"]
4+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/node_modules
2+
/buildOutput
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<html>
2+
<head></head>
3+
<body>
4+
<script src="js/commons.js" charset="utf-8"></script>
5+
<script src="js/admin-commons.js" charset="utf-8"></script>
6+
<script src="js/adminPageA.js" charset="utf-8"></script>
7+
</body>
8+
</html>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require("./modules/a-b-c");
2+
require("./modules/admin");
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require("./modules/a-b-c");
2+
require("./modules/admin");
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require("./modules/a-b-c");
2+
require("./modules/admin");
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "Common";
Loading
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "a-b-c module content";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "a-b module content";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "a-c module content";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "admin module content";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "b-c module content";
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "webpack-multiple-commons-chunks",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"clear": "rimraf buildOutput",
8+
"prebuild": "npm run clear",
9+
"build": "webpack",
10+
"start": "npm run build"
11+
},
12+
"author": "",
13+
"license": "ISC",
14+
"devDependencies": {
15+
"opener": "^1.4.2",
16+
"rimraf": "^2.5.4",
17+
"webpack": "^1.13.3"
18+
},
19+
"reference": [
20+
"https://github.com/webpack/webpack/tree/master/examples/multiple-commons-chunks",
21+
"https://webpack.github.io/docs/list-of-plugins.html#commonschunkplugin",
22+
"https://webpack.js.org/plugins/commons-chunk-plugin/",
23+
"https://github.com/webpack/webpack/tree/master/examples/common-chunk-and-vendor-chunk"
24+
]
25+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<html>
2+
<head></head>
3+
<body>
4+
<script src="js/commons.js" charset="utf-8"></script>
5+
<script src="js/pageA.js" charset="utf-8"></script>
6+
</body>
7+
</html>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require("./modules/a-b-c");
2+
require("./modules/a-b");
3+
require("./modules/a-c");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require("./modules/a-b-c");
2+
require("./modules/a-b");
3+
require("./modules/b-c");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require("./modules/a-b-c");
2+
require("./modules/b-c");
3+
require("./modules/a-c");
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
var path = require("path");
2+
3+
var webpack = require("webpack");
4+
5+
module.exports = {
6+
entry: {
7+
pageA: "./pageA",//a-b-c + a-b + a-c
8+
pageB: "./pageB",//a-b-c + a-b + b-c
9+
pageC: "./pageC",//a-b-c + a-c + b-c
10+
adminPageA: "./adminPageA",//a-b-c + admin
11+
adminPageB: "./adminPageB",//a-b-c + admin
12+
adminPageC: "./adminPageC",//a-b-c + admin
13+
},
14+
15+
output: {
16+
path: path.join(__dirname, "buildOutput"),
17+
filename: "[name].js"
18+
},
19+
20+
// plugins: [
21+
// new webpack.optimize.CommonsChunkPlugin("admin-commons.js", ["adminPageA", "adminPageB"]),
22+
// new webpack.optimize.CommonsChunkPlugin("commons.js", ["pageA", "pageB", "admin-commons.js"], 2),
23+
// new webpack.optimize.CommonsChunkPlugin("c-commons.js", ["pageC", "adminPageC"]),
24+
// ]
25+
26+
plugins: [
27+
new webpack.optimize.CommonsChunkPlugin({
28+
name: "admin-commons",
29+
chunks: ["adminPageA", "adminPageB"]
30+
}),
31+
new webpack.optimize.CommonsChunkPlugin({
32+
name: "commons",
33+
chunks: ["pageA", "pageB", "admin-commons"],
34+
minChunks: 2
35+
}),
36+
new webpack.optimize.CommonsChunkPlugin({
37+
name: "c-commons",
38+
chunks: ["pageC", "adminPageC"]
39+
})
40+
]
41+
};

0 commit comments

Comments
 (0)