Skip to content
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

Merged
merged 16 commits into from
Aug 21, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(migrate): CCP to SCP - multiple instances
  • Loading branch information
dhruvdutt committed Aug 8, 2018
commit 41534710987d51431570970bd59f65331aea261c
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,81 @@ exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-7" da
}
"
`;

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

vendor: {
name: 'vendor',
chunks: 'initial',
enforce: true,
test: '/node_modules/'
},

app: {
name: 'app',
chunks: 'initial',
enforce: true
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks correct to me

}
}
}
}
"
`;

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

app: {
name: 'app',
chunks: 'initial',
enforce: true
}
}
},

runtimeChunk: true
}
}
"
`;

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

runtime: {
name: 'runtime',
chunks: 'initial',
enforce: true
}
}
}
}
}
"
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.export = {
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: "app"
}),
new webpack.optimize.CommonsChunkPlugin({
name: "runtime"
})
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.export = {
plugins: [
new webpack.optimize.CommonsChunkPlugin({
names: ["main", "vendor"]
}),
new webpack.optimize.CommonsChunkPlugin({
name: "app"
})
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.export = {
plugins: [
new webpack.optimize.CommonsChunkPlugin({
names: ["main", "runtime"]
}),
new webpack.optimize.CommonsChunkPlugin({
name: "app"
})
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ defineTest(__dirname, "commonsChunkPlugin", "commonsChunkPlugin-4");
defineTest(__dirname, "commonsChunkPlugin", "commonsChunkPlugin-5");
defineTest(__dirname, "commonsChunkPlugin", "commonsChunkPlugin-6");
defineTest(__dirname, "commonsChunkPlugin", "commonsChunkPlugin-7");
defineTest(__dirname, "commonsChunkPlugin", "commonsChunkPlugin-8");
defineTest(__dirname, "commonsChunkPlugin", "commonsChunkPlugin-9");
defineTest(__dirname, "commonsChunkPlugin", "commonsChunkPlugin-10");
9 changes: 7 additions & 2 deletions packages/migrate/commonsChunkPlugin/commonsChunkPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,20 @@ export default function(j: IJSCodeshift, ast: INode): INode {
}

// cache group options based on keys
const cacheGroup: object = {};
const cacheGroups: INode[] = [];
let cacheGroup: object = {};
let cacheGroups: INode[] = [];
let isAsyncChunk: boolean = false;

// iterate each CommonsChunkPlugin instance
CommonsChunkPlugin.forEach(
(path: INode): void => {
const CCPProps: INode[] = path.value.arguments[0].properties;

// reset chunks from old props
cacheGroup = {};
cacheGroups = [];
isAsyncChunk = false;

let chunkKey: string;

// iterate CCP props and map SCP props
Expand Down