Skip to content

Commit

Permalink
feat(migrate): CCP to SCP - fix minSize, async chunk
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvdutt committed Aug 20, 2018
1 parent e404f3b commit b751e62
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@ exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-0" da
cacheGroups: {
app: {
name: 'app',
chunks: 'initial',
enforce: true,
test: 'app'
},
vendor: {
name: 'vendor',
chunks: 'initial',
enforce: true,
test: 'vendor'
}
}
Expand All @@ -40,15 +36,11 @@ exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-1" da
splitChunks: {
cacheGroups: {
common: {
name: 'common',
chunks: 'initial',
enforce: true
name: 'common'
},
vendor: {
name: 'vendor',
chunks: 'initial',
enforce: true,
test: 'vendor'
}
}
Expand All @@ -69,8 +61,6 @@ exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-2" da
cacheGroups: {
vendor: {
name: 'vendor',
chunks: 'initial',
enforce: true,
test: 'vendor'
}
}
Expand All @@ -87,8 +77,6 @@ exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-3" da
cacheGroups: {
commons: {
name: 'commons',
chunks: 'initial',
enforce: true,
filename: 'commons.js'
}
}
Expand All @@ -106,13 +94,12 @@ exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-4" da
optimizations: {
splitChunks: {
chunks: 'async',
minSize: 2000,
cacheGroups: {
main: {
name: 'main',
test: 'main'
test: 'main',
chunks: 'async',
minSize: 2000
}
}
}
Expand All @@ -132,8 +119,6 @@ exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-5" da
cacheGroups: {
main: {
name: 'main',
chunks: 'initial',
enforce: true,
test: 'main'
}
}
Expand All @@ -158,8 +143,6 @@ exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-6a" d
cacheGroups: {
main: {
name: 'main',
chunks: 'initial',
enforce: true,
test: module => {
if (module.getChunks().some(chunk => chunk.name === 'main'))
Expand Down Expand Up @@ -187,8 +170,6 @@ exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-6b" d
cacheGroups: {
main: {
name: 'main',
chunks: 'initial',
enforce: true,
test: module => {
if (module.getChunks().some(chunk => chunk.name === 'main'))
Expand Down Expand Up @@ -220,8 +201,6 @@ exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-6c" d
cacheGroups: {
main: {
name: 'main',
chunks: 'initial',
enforce: true,
test: module => {
if (module.getChunks().some(chunk => chunk.name === 'main'))
Expand Down Expand Up @@ -253,8 +232,6 @@ exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-6d" d
cacheGroups: {
main: {
name: 'main',
chunks: 'initial',
enforce: true,
test: module => {
if (module.getChunks().some(chunk => chunk.name === 'main'))
Expand Down Expand Up @@ -286,14 +263,11 @@ exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-7" da
optimizations: {
splitChunks: {
minSize: 3000,
cacheGroups: {
main: {
name: 'main',
chunks: 'initial',
enforce: true,
test: 'main'
test: 'main',
minSize: 3000
}
}
}
Expand Down
19 changes: 10 additions & 9 deletions packages/migrate/commonsChunkPlugin/commonsChunkPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export default function(j: IJSCodeshift, ast: INode): INode {
// cache group options based on keys
let cacheGroup: object = {};
let cacheGroups: INode[] = [];
let isAsyncChunk: boolean = false;

// iterate each CommonsChunkPlugin instance
CommonsChunkPlugin.forEach(
Expand All @@ -50,7 +49,6 @@ export default function(j: IJSCodeshift, ast: INode): INode {
// reset chunks from old props
cacheGroup = {};
cacheGroups = [];
isAsyncChunk = false;
commonCacheGroupsProps = [
createProperty(j, "chunks", "initial"),
createProperty(j, "enforce", true),
Expand Down Expand Up @@ -133,12 +131,19 @@ export default function(j: IJSCodeshift, ast: INode): INode {
break;

case "async":
splitChunksProps.push(createProperty(j, "chunks", "async"));
isAsyncChunk = true;
if (!Array.isArray(cacheGroup[chunkKey])) {
cacheGroup[chunkKey] = [];
}
cacheGroup[chunkKey].push(
createProperty(j, "chunks", "async"),
);
break;

case "minSize":
splitChunksProps.push(
if (!Array.isArray(cacheGroup[chunkKey])) {
cacheGroup[chunkKey] = [];
}
cacheGroup[chunkKey].push(
j.property("init", createIdentifierOrLiteral(j, propKey), p.value),
);
break;
Expand Down Expand Up @@ -170,10 +175,6 @@ export default function(j: IJSCodeshift, ast: INode): INode {

const chunkPropsToAdd = cacheGroup[chunkName];

if (!isAsyncChunk) {
chunkProps.push(...commonCacheGroupsProps);
}

if (chunkCount > 1) {
chunkProps.push(
j.property(
Expand Down

0 comments on commit b751e62

Please sign in to comment.