Skip to content

Commit

Permalink
feat(migrate): CCP to SCP - regex support, minChunks, async chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvdutt committed Aug 7, 2018
1 parent 3afc80a commit 36fe9cc
Show file tree
Hide file tree
Showing 6 changed files with 275 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,31 +89,107 @@ exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-4" da
"module.export = {
optimizations: {
splitChunks: {
chunks: 'async',
minSize: 0,
minChunks: 2,
cacheGroups: {
main: {
chunks: 'initial',
enforce: true,
name: 'main'
}
}
}
}
}
"
`;

exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-5" data 1`] = `
"module.export = {
optimizations: {
splitChunks: {
cacheGroups: {
main: {
chunks: 'initial',
enforce: true,
name: 'main'
}
}
},
runtimeChunk: true
}
}
"
`;

exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-6" data 1`] = `
"module.export = {
optimizations: {
splitChunks: {
cacheGroups: {
main: {
chunks: 'initial',
enforce: true,
name: 'main'
},
chunks: 'initial',
enforce: true,
name: true
name: {
chunks: 'initial',
enforce: true,
name: 'name',
test: ({ resource }) => /node_modules/.test(resource),
test: ({ resource }) => {
var foo = \\"bar\\";
return /node_modules/.test(resource);
},
test: function ({ resource }) {
var foo = \\"bar\\";
return /node_modules/.test(resource);
},
test: function ({ resource }) {
var foo = \\"bar\\";
if (foo) {
return /node_modulesfoo/.test(resource);
} else if (foo === \\"something\\") {
return /node_modulesbar/.test(resource);
} else {
return /node_modulesbaz/.test(resource);
}
}
}
}
}
}
}
"
`;

exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-5" data 1`] = `
exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-7" data 1`] = `
"module.export = {
optimizations: {
splitChunks: {
runtimeChunk: true
minChunks: Infinity,
cacheGroups: {
main: {
chunks: 'initial',
enforce: true,
name: 'main'
},
vendor: {
chunks: 'initial',
enforce: true,
name: 'vendor',
test: '/node_modules/'
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.export = {
plugins: [
new webpack.optimize.CommonsChunkPlugin({
names: ["runtime"],
names: ["main", "runtime"],
})
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.export = {
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: "main",
minChunks: ({ resource }) => /node_modules/.test(resource),
minChunks: ({ resource }) => {
var foo = "bar";
return /node_modules/.test(resource);
},
minChunks: function ({ resource }) {
var foo = "bar";
return /node_modules/.test(resource);
},
minChunks: function ({ resource }) {
var foo = "bar";
if (foo) {
return /node_modulesfoo/.test(resource);
} else if (foo === "something") {
return /node_modulesbar/.test(resource);
} else {
return /node_modulesbaz/.test(resource);
}
}
})
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.export = {
plugins: [
new webpack.optimize.CommonsChunkPlugin({
names: ["main", "vendor"],
minChunks: Infinity,
}),
// new webpack.optimize.CommonsChunkPlugin({
// name: "vendor",
// }),
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ defineTest(__dirname, "commonsChunkPlugin", "commonsChunkPlugin-2");
defineTest(__dirname, "commonsChunkPlugin", "commonsChunkPlugin-3");
defineTest(__dirname, "commonsChunkPlugin", "commonsChunkPlugin-4"); // todo fix async case
defineTest(__dirname, "commonsChunkPlugin", "commonsChunkPlugin-5");
// defineTest(__dirname, "commonsChunkPlugin", "commonsChunkPlugin-6");
// defineTest(__dirname, "commonsChunkPlugin", "commonsChunkPlugin-7");
defineTest(__dirname, "commonsChunkPlugin", "commonsChunkPlugin-6");
defineTest(__dirname, "commonsChunkPlugin", "commonsChunkPlugin-7");
Loading

0 comments on commit 36fe9cc

Please sign in to comment.