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

Conversation

dhruvdutt
Copy link
Member

@dhruvdutt dhruvdutt commented Jul 31, 2018

What kind of change does this PR introduce?
Feature

Did you add tests for your changes?
Yes

If relevant, did you update the documentation?
No

Summary
Initial implementation for migration CCP to SCP.

It is not possible to map all the options/properties from CCP to SCP migration. It's best to do a basic migration optimization.splitChunks object migration and give a link to docs, migration guide and allow the user the flexibility to make more adjustments/optimizations with newer options available in SCP. Also, many common use-cases directly work out of the box in the new SCP plugin.

TODO:

  • TBD cases

Does this PR introduce a breaking change?
No

Other information

Closes #393

@webpack webpack deleted a comment from webpack-bot Jul 31, 2018
@dhruvdutt dhruvdutt force-pushed the migrate branch 3 times, most recently from a8ebc1d to e4fb993 Compare August 1, 2018 10:46
@dhruvdutt dhruvdutt changed the title [WIP] feat(migrate): commonChunksPlugin to SplitChunksPlugin [WIP] feat(migrate): CommonChunksPlugin to SplitChunksPlugin Aug 1, 2018
Copy link
Member

@evenstensberg evenstensberg left a comment

Choose a reason for hiding this comment

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

Left some comments and I think @sokra should be looking at the end output here too

pluginProps.forEach((p: INode) => {
switch (p.key.name) {
case "names":
p.value.elements.forEach((chunkName) => {
Copy link
Member

Choose a reason for hiding this comment

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

returns void

];
switch (chunkName.value) {
case "vendor":
return j.property(
Copy link
Member

Choose a reason for hiding this comment

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

this is not always the case, user supplies the regex

Copy link
Member Author

Choose a reason for hiding this comment

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

Can you please give an example syntax of how the user supplies the regex? I can't find it in the CommonsChunkPlugin docs

Copy link
Member Author

Choose a reason for hiding this comment

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

If user supplies the test prop they can regex chunks

I can't find that option in the older CommonsChunkPlugin docs. test is supported in SplitChunksPlugin docs.

Copy link
Member

Choose a reason for hiding this comment

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

No need to take review comments for actual comments. A regex to match a chunk was possible in v.2 if I recall right. @sokra needs to guide you here, I don't fully know backwards compat spec


// create chunk cache group option
function createChunkCache(chunkName) {
const commonProperties = [
Copy link
Member

Choose a reason for hiding this comment

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

missing type

@@ -0,0 +1,3 @@
[*]
Copy link
Member

Choose a reason for hiding this comment

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

drop this

@evenstensberg
Copy link
Member

If user supplies the test prop they can regex chunks

@dhruvdutt dhruvdutt force-pushed the migrate branch 2 times, most recently from ebf2a98 to 846cc5a Compare August 7, 2018 13:12
@webpack-bot
Copy link

Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon.

minChunks: 1,
test: 'vendor'
}
}
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

name: 'commons',
chunks: 'initial',
enforce: true,
minChunks: 1,
Copy link
Member

Choose a reason for hiding this comment

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

minChunks should be the number of defined entrypoints.

optimizations: {
splitChunks: {
chunks: 'async',
minSize: 2000,
Copy link
Member

Choose a reason for hiding this comment

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

I would move this into the cacheGroups.main

Copy link
Member

Choose a reason for hiding this comment

The 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'
                }
            }

enforce: true,
minChunks: 1,
test: 'main'
}
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

enforce: true,
minChunks: 1,
test: 'main',
test: ({ resource }) => /node_modules/.test(resource)
Copy link
Member

Choose a reason for hiding this comment

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

You can't have test multiple times in the config.

You could be merged this way:

test: module => {
  if(module.getChunks().some(chunk => chunk.name === 'main')) return true;
  const fn = ({ resource }) => /node_modules/.test(resource);
  return fn(module);
}

minChunks: 1,
test: 'main',

test: ({ resource }) => {
Copy link
Member

Choose a reason for hiding this comment

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

same

minChunks: 1,
test: 'main',

test: function ({ resource }) {
Copy link
Member

Choose a reason for hiding this comment

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

same

minChunks: 1,
test: 'main',

test: function ({ resource }) {
Copy link
Member

Choose a reason for hiding this comment

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

same

chunks: 'async',

cacheGroups: {
minSize: 2000,
Copy link
Member

Choose a reason for hiding this comment

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

This is incorrect and will fail the validation.


const fn = ({ resource }) => /node_modules/.test(resource);
return fn(module);
}
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

};

return fn(module);
}
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


return fn(module);
}
}
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

};

return fn(module);
}
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

optimizations: {
splitChunks: {
cacheGroups: {
minSize: 3000,
Copy link
Member

Choose a reason for hiding this comment

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

Same

name: 'main',
chunks: 'initial',
enforce: true,
minChunks: 1,
Copy link
Member

Choose a reason for hiding this comment

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

You don't need minChunks: 1 when using enforce: true

minChunks: 2,
test: 'vendor'
}
}
Copy link
Member

Choose a reason for hiding this comment

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

In this case runtimeChunk: { name: "vendor" } makes sense.

Copy link
Member Author

Choose a reason for hiding this comment

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

The input webpack config doesn't have runtime anywhere. How to identify when to apply runtimeChunk?

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
		})
	]
}

name: 'vendor',
chunks: 'initial',
enforce: true,
minChunks: 2,
Copy link
Member

Choose a reason for hiding this comment

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

minChunks: 2 is incorrect here.

When using test: "string", minChunks should not be set.

Copy link
Member

@sokra sokra left a comment

Choose a reason for hiding this comment

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

A few minor issues, otherwise it's good enough...

optimizations: {
splitChunks: {
chunks: 'async',
minSize: 2000,
Copy link
Member

Choose a reason for hiding this comment

The 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'
                }
            }


optimizations: {
splitChunks: {
minSize: 3000,
Copy link
Member

Choose a reason for hiding this comment

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

This need to be moved into cacheGroups.main

Copy link
Member Author

@dhruvdutt dhruvdutt Aug 20, 2018

Choose a reason for hiding this comment

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

Resolved.

@dhruvdutt dhruvdutt changed the title [WIP] feat(migrate): CommonChunksPlugin to SplitChunksPlugin feat(migrate): CommonChunksPlugin to SplitChunksPlugin Aug 20, 2018
Copy link
Member

@evenstensberg evenstensberg left a comment

Choose a reason for hiding this comment

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

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants