-
-
Notifications
You must be signed in to change notification settings - Fork 617
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 15 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,303 @@ | ||
// 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' | ||
} | ||
} | ||
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. In this case 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. The input webpack config doesn't have This is the input case for this output: module.exports = {
entry: {
app: './src/app.js',
vendor: './src/vendors.js',
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
names: ["app", "vendor"],
minChunks: 2
})
]
} |
||
} | ||
} | ||
} | ||
" | ||
`; | ||
|
||
exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-1" data 1`] = ` | ||
"module.exports = { | ||
entry: { | ||
vendor: './src/vendors.js', | ||
}, | ||
|
||
optimizations: { | ||
splitChunks: { | ||
cacheGroups: { | ||
common: { | ||
name: 'common', | ||
chunks: 'initial', | ||
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. The default |
||
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' | ||
} | ||
} | ||
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-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: { | ||
chunks: 'async', | ||
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. Don't do it globally 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. What would CCP 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. I think inside the cacheGroups splitChunks: {
cacheGroups: {
chunks: 'async'
}
} 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. As per the docs: js
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. Yes I know, but in |
||
minSize: 2000, | ||
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. I would move this into the 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. Still not resolved. This case is not 100% map-able to splitChunks. This might be the best option: cacheGroups: {
main: {
minSize: 2000,
chunks: 'async'
}
} |
||
|
||
cacheGroups: { | ||
main: { | ||
name: 'main', | ||
test: 'main' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
" | ||
`; | ||
|
||
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' | ||
} | ||
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 |
||
} | ||
}, | ||
|
||
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: { | ||
minSize: 3000, | ||
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. This need to be moved into 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. Resolved. |
||
|
||
cacheGroups: { | ||
main: { | ||
name: 'main', | ||
chunks: 'initial', | ||
enforce: true, | ||
test: 'main' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
" | ||
`; |
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.
add
minChunks: 2
here