Do you want to request a feature or report a bug?
bug
What is the current behavior?
When configuring the plugin with children:true, or async:true it will only work as expected I manually specify whose entry's children depedencies I want to extract. That is, i must specify name or names to make it work
If the current behavior is a bug, please provide the steps to reproduce.
Here is a gist with a sample configuration
https://gist.github.com/mcortesi/ec005ce129abb73b6b2a015baf615998
We have:
- only one entry:
fileA
fileA uses require.ensure to include ch1, ch2, ch3.
- all
ch* include commonsB module
webpack.config has the CommonChunkPlugin with:
new webpack.optimize.CommonsChunkPlugin({
children: true,
async: true
}),
What is the expected behavior?
commonsB since is a shared module of all children must be included within fileA and not in each children.
Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.
webpack: "^3.4.1"
Analysis
sorry, didn't find where to put this in the template 🙄
I read & debug the code. The problem as I see it is that getTargetChunks() should resolve to the names of the commons chunk. So, if we specify a name it uses it, but if we don't it just creates a new chunk.
If you see here https://github.com/webpack/webpack/blob/master/lib/optimize/CommonsChunkPlugin.js#L178-L212
it does:
- if we specified a name, it uses the entry already exist for it, or it creates a new one
- if we didn't specify a name, but we have async or children, we return all chunks that are not initial. (in my example that would be
ch*)
- else throws
Then code then iterates over each targetChunk (a common chunk), and computes the affectedChunks (those we will look for common modules), and extract the modules.
And in the case of children or async the getAffectedChunks returns the children of the targetChunk, that as i said above is already the child chunk, so it doesn't have any.
Possible Solution
I didn't send a PR since i don't know if i got this correctly. But my guess is that name must be required as an option. and this if should be removed. I doesn't make sense to me.
Do you want to request a feature or report a bug?
bug
What is the current behavior?
When configuring the plugin with
children:true, orasync:trueit will only work as expected I manually specify whose entry's children depedencies I want to extract. That is, i must specifynameornamesto make it workIf the current behavior is a bug, please provide the steps to reproduce.
Here is a gist with a sample configuration
https://gist.github.com/mcortesi/ec005ce129abb73b6b2a015baf615998
We have:
fileAfileAusesrequire.ensureto includech1,ch2,ch3.ch*includecommonsBmodulewebpack.confighas the CommonChunkPlugin with:What is the expected behavior?
commonsBsince is a shared module of all children must be included withinfileAand not in each children.Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.
webpack: "^3.4.1"
Analysis
sorry, didn't find where to put this in the template 🙄
I read & debug the code. The problem as I see it is that
getTargetChunks()should resolve to the names of the commons chunk. So, if we specify a name it uses it, but if we don't it just creates a new chunk.If you see here https://github.com/webpack/webpack/blob/master/lib/optimize/CommonsChunkPlugin.js#L178-L212
it does:
ch*)Then code then iterates over each targetChunk (a common chunk), and computes the affectedChunks (those we will look for common modules), and extract the modules.
And in the case of
childrenorasyncthegetAffectedChunksreturns the children of the targetChunk, that as i said above is already the child chunk, so it doesn't have any.Possible Solution
I didn't send a PR since i don't know if i got this correctly. But my guess is that
namemust be required as an option. and this if should be removed. I doesn't make sense to me.