Skip to content

Commit c2982a8

Browse files
authored
Merge pull request jantimon#343 from ampedandwired/fixes/dependency-sort
Exclude chunks works now even if combined with dependency sort
2 parents f3e4ead + c542735 commit c2982a8

File tree

4 files changed

+38
-4
lines changed

4 files changed

+38
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Change History
22
==============
33

4+
v2.20.0
5+
----
6+
* Exclude chunks works now even if combined with dependency sort
7+
48
v2.19.0
59
----
610
* Add `html-webpack-plugin-alter-chunks` event for custom chunk sorting and interpolation

lib/chunksorter.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ module.exports.dependency = function (chunks) {
4141
// Add an edge for each parent (parent -> child)
4242
chunk.parents.forEach(function (parentId) {
4343
var parentChunk = nodeMap[parentId];
44-
if (!parentChunk) {
45-
throw new Error('Can not find chunk parent during dependency sort');
44+
// If the parent chunk does not exist (e.g. because of an excluded chunk)
45+
// we ignore that parent
46+
if (parentChunk) {
47+
edges.push([parentChunk, chunk]);
4648
}
47-
edges.push([parentChunk, chunk]);
4849
});
4950
}
5051
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "html-webpack-plugin",
3-
"version": "2.19.0",
3+
"version": "2.20.0",
44
"description": "Simplifies creation of HTML files to serve your webpack bundles",
55
"main": "index.js",
66
"files": [

spec/BasicSpec.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,35 @@ describe('HtmlWebpackPlugin', function () {
11631163
/<script type="text\/javascript" src="common_bundle.js">.+<script type="text\/javascript" src="aTheme_bundle.js">.+<script type="text\/javascript" src="util_bundle.js">/], null, done);
11641164
});
11651165

1166+
it('should sort the chunks by chunk dependencies even if a parent chunk is excluded', function (done) {
1167+
testHtmlPlugin({
1168+
entry: {
1169+
util: path.join(__dirname, 'fixtures/util.js'),
1170+
aTheme: path.join(__dirname, 'fixtures/theme.js')
1171+
},
1172+
output: {
1173+
path: OUTPUT_DIR,
1174+
filename: '[name]_bundle.js'
1175+
},
1176+
module: {
1177+
loaders: [
1178+
{ test: /\.css$/, loader: 'css-loader' }
1179+
]
1180+
},
1181+
plugins: [
1182+
new CommonsChunkPlugin({
1183+
name: 'common',
1184+
filename: 'common_bundle.js'
1185+
}),
1186+
new HtmlWebpackPlugin({
1187+
chunksSortMode: 'dependency',
1188+
excludeChunks: ['common']
1189+
})
1190+
]
1191+
}, [
1192+
/<script type="text\/javascript" src="aTheme_bundle.js">.+<script type="text\/javascript" src="util_bundle.js">/], null, done);
1193+
});
1194+
11661195
it('should add the webpack compilation object as a property of the templateParam object', function (done) {
11671196
testHtmlPlugin({
11681197
entry: path.join(__dirname, 'fixtures/index.js'),

0 commit comments

Comments
 (0)