-
-
Notifications
You must be signed in to change notification settings - Fork 611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(migrate): CommonChunksPlugin to SplitChunksPlugin #558
Changes from all commits
ecf8679
3d9d31c
303857b
b4cdd03
6329aaa
bde0049
4153471
53fcea1
4fe0db3
db22fcc
08eff34
b671af5
1e441e3
b68a7d0
e404f3b
2d63478
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,302 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-0" data 1`] = ` | ||
"module.exports = { | ||
entry: { | ||
app: './src/app.js', | ||
vendor: './src/vendors.js', | ||
}, | ||
|
||
optimizations: { | ||
splitChunks: { | ||
cacheGroups: { | ||
app: { | ||
name: 'app', | ||
chunks: 'initial', | ||
enforce: true, | ||
test: 'app' | ||
}, | ||
|
||
vendor: { | ||
name: 'vendor', | ||
chunks: 'initial', | ||
enforce: true, | ||
test: 'vendor' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
" | ||
`; | ||
|
||
exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-1" data 1`] = ` | ||
"module.exports = { | ||
entry: { | ||
vendor: './src/vendors.js', | ||
}, | ||
|
||
optimizations: { | ||
splitChunks: { | ||
cacheGroups: { | ||
common: { | ||
name: 'common', | ||
chunks: 'initial', | ||
enforce: true | ||
}, | ||
|
||
vendor: { | ||
name: 'vendor', | ||
chunks: 'initial', | ||
enforce: true, | ||
test: 'vendor' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
" | ||
`; | ||
|
||
exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-2" data 1`] = ` | ||
"module.exports = { | ||
entry: { | ||
vendor: './src/vendors.js', | ||
}, | ||
|
||
optimizations: { | ||
splitChunks: { | ||
cacheGroups: { | ||
vendor: { | ||
name: 'vendor', | ||
chunks: 'initial', | ||
enforce: true, | ||
test: 'vendor' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
" | ||
`; | ||
|
||
exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-3" data 1`] = ` | ||
"module.exports = { | ||
optimizations: { | ||
splitChunks: { | ||
cacheGroups: { | ||
commons: { | ||
name: 'commons', | ||
chunks: 'initial', | ||
This comment was marked as resolved.
Sorry, something went wrong. |
||
enforce: true, | ||
filename: 'commons.js' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
" | ||
`; | ||
|
||
exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-4" data 1`] = ` | ||
"module.exports = { | ||
entry: { | ||
main: './src/index.js', | ||
}, | ||
|
||
optimizations: { | ||
splitChunks: { | ||
cacheGroups: { | ||
main: { | ||
name: 'main', | ||
enforce: true, | ||
test: 'main', | ||
chunks: 'async', | ||
minSize: 2000 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
" | ||
`; | ||
|
||
exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-5" data 1`] = ` | ||
"module.exports = { | ||
entry: { | ||
main: './src/index.js', | ||
}, | ||
|
||
optimizations: { | ||
splitChunks: { | ||
cacheGroups: { | ||
main: { | ||
name: 'main', | ||
chunks: 'initial', | ||
enforce: true, | ||
test: 'main' | ||
} | ||
} | ||
}, | ||
|
||
runtimeChunk: { | ||
name: 'runtime' | ||
} | ||
} | ||
} | ||
" | ||
`; | ||
|
||
exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-6a" data 1`] = ` | ||
"module.exports = { | ||
entry: { | ||
main: './src/index.js', | ||
}, | ||
|
||
optimizations: { | ||
splitChunks: { | ||
cacheGroups: { | ||
main: { | ||
name: 'main', | ||
chunks: 'initial', | ||
enforce: true, | ||
|
||
test: module => { | ||
if (module.getChunks().some(chunk => chunk.name === 'main')) | ||
return true; | ||
|
||
const fn = ({ resource }) => /node_modules/.test(resource); | ||
return fn(module); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks correct to me |
||
} | ||
} | ||
} | ||
} | ||
} | ||
" | ||
`; | ||
|
||
exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-6b" data 1`] = ` | ||
"module.exports = { | ||
entry: { | ||
main: './src/index.js', | ||
}, | ||
|
||
optimizations: { | ||
splitChunks: { | ||
cacheGroups: { | ||
main: { | ||
name: 'main', | ||
chunks: 'initial', | ||
enforce: true, | ||
|
||
test: module => { | ||
if (module.getChunks().some(chunk => chunk.name === 'main')) | ||
return true; | ||
|
||
const fn = ({ resource }) => { | ||
// some code | ||
return /node_modules/.test(resource); | ||
}; | ||
|
||
return fn(module); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks correct to me |
||
} | ||
} | ||
} | ||
} | ||
} | ||
" | ||
`; | ||
|
||
exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-6c" data 1`] = ` | ||
"module.exports = { | ||
entry: { | ||
main: './src/index.js', | ||
}, | ||
|
||
optimizations: { | ||
splitChunks: { | ||
cacheGroups: { | ||
main: { | ||
name: 'main', | ||
chunks: 'initial', | ||
enforce: true, | ||
|
||
test: module => { | ||
if (module.getChunks().some(chunk => chunk.name === 'main')) | ||
return true; | ||
|
||
const fn = function ({ resource }) { | ||
// some code | ||
return /node_modules/.test(resource); | ||
}; | ||
|
||
return fn(module); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks correct to me |
||
} | ||
} | ||
} | ||
} | ||
" | ||
`; | ||
|
||
exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-6d" data 1`] = ` | ||
"module.exports = { | ||
entry: { | ||
main: './src/index.js', | ||
}, | ||
|
||
optimizations: { | ||
splitChunks: { | ||
cacheGroups: { | ||
main: { | ||
name: 'main', | ||
chunks: 'initial', | ||
enforce: true, | ||
|
||
test: module => { | ||
if (module.getChunks().some(chunk => chunk.name === 'main')) | ||
return true; | ||
|
||
const fn = function ({ resource }) { | ||
if (foo) { | ||
return /node_modulesfoo/.test(resource); | ||
} else { | ||
return /node_modulesbaz/.test(resource); | ||
} | ||
}; | ||
|
||
return fn(module); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks correct to me |
||
} | ||
} | ||
} | ||
} | ||
} | ||
" | ||
`; | ||
|
||
exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-7" data 1`] = ` | ||
"module.exports = { | ||
entry: { | ||
main: './src/index.js', | ||
}, | ||
|
||
optimizations: { | ||
splitChunks: { | ||
cacheGroups: { | ||
main: { | ||
name: 'main', | ||
chunks: 'initial', | ||
enforce: true, | ||
test: 'main', | ||
minSize: 3000 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
" | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module.exports = { | ||
entry: { | ||
app: './src/app.js', | ||
vendor: './src/vendors.js', | ||
}, | ||
plugins: [ | ||
new webpack.optimize.CommonsChunkPlugin({ | ||
names: ["app", "vendor"], | ||
minChunks: 2 | ||
}) | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module.exports = { | ||
entry: { | ||
vendor: './src/vendors.js', | ||
}, | ||
|
||
plugins: [ | ||
new webpack.optimize.CommonsChunkPlugin({ | ||
names: ["common", "vendor"] | ||
}) | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module.exports = { | ||
entry: { | ||
vendor: './src/vendors.js', | ||
}, | ||
|
||
plugins: [ | ||
new webpack.optimize.CommonsChunkPlugin({ | ||
names: ["vendor"] | ||
}) | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = { | ||
plugins: [ | ||
new webpack.optimize.CommonsChunkPlugin({ | ||
name: "commons", | ||
filename: "commons.js", | ||
}) | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = { | ||
entry: { | ||
main: './src/index.js', | ||
}, | ||
|
||
plugins: [ | ||
new webpack.optimize.CommonsChunkPlugin({ | ||
name: "main", | ||
async: true, | ||
minSize: 2000, | ||
}) | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module.exports = { | ||
entry: { | ||
main: './src/index.js', | ||
}, | ||
|
||
plugins: [ | ||
new webpack.optimize.CommonsChunkPlugin({ | ||
names: ["main", "runtime"], | ||
}) | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module.exports = { | ||
entry: { | ||
main: './src/index.js', | ||
}, | ||
|
||
plugins: [ | ||
new webpack.optimize.CommonsChunkPlugin({ | ||
name: "main", | ||
minChunks: ({ resource }) => /node_modules/.test(resource), | ||
}) | ||
] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default
minChunks
for the CCP is the number of selected chunks. So you may count the number of entrypoints here.