diff --git a/packages/migrate/commonsChunkPlugin/__snapshots__/commonsChunkPlugin.test.js.snap b/packages/migrate/commonsChunkPlugin/__snapshots__/commonsChunkPlugin.test.js.snap index c9b1ec5c332..baddb3a7530 100644 --- a/packages/migrate/commonsChunkPlugin/__snapshots__/commonsChunkPlugin.test.js.snap +++ b/packages/migrate/commonsChunkPlugin/__snapshots__/commonsChunkPlugin.test.js.snap @@ -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' } } @@ -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' } } @@ -69,8 +61,6 @@ exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-2" da cacheGroups: { vendor: { name: 'vendor', - chunks: 'initial', - enforce: true, test: 'vendor' } } @@ -87,8 +77,6 @@ exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-3" da cacheGroups: { commons: { name: 'commons', - chunks: 'initial', - enforce: true, filename: 'commons.js' } } @@ -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 } } } @@ -132,8 +119,6 @@ exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-5" da cacheGroups: { main: { name: 'main', - chunks: 'initial', - enforce: true, test: 'main' } } @@ -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')) @@ -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')) @@ -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')) @@ -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')) @@ -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 } } } diff --git a/packages/migrate/commonsChunkPlugin/commonsChunkPlugin.ts b/packages/migrate/commonsChunkPlugin/commonsChunkPlugin.ts index c91e51fe305..b32f1f7eccd 100644 --- a/packages/migrate/commonsChunkPlugin/commonsChunkPlugin.ts +++ b/packages/migrate/commonsChunkPlugin/commonsChunkPlugin.ts @@ -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( @@ -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), @@ -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; @@ -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(