html-webpack-plugin
Advanced tools
Comparing version 2.0.4 to 2.1.0
41
index.js
@@ -59,2 +59,4 @@ 'use strict'; | ||
var chunks = self.filterChunks(compilation.getStats().toJson(), self.options.chunks, self.options.excludeChunks); | ||
// Sort chunks | ||
chunks = self.sortChunks(chunks, self.options.chunksSortMode); | ||
// Get assets | ||
@@ -295,6 +297,32 @@ var assets = self.htmlWebpackPluginAssets(compilation, chunks); | ||
/** | ||
* Helper to sort chunks | ||
*/ | ||
HtmlWebpackPlugin.prototype.sortChunks = function(chunks, sortMode) { | ||
// Sort mode auto by default: | ||
if (typeof sortMode === 'undefined' || sortMode === 'auto') { | ||
return chunks.sort(function orderEntryLast(a, b) { | ||
if (a.entry !== b.entry) { | ||
return b.entry ? 1 : -1; | ||
} else { | ||
return b.id - a.id; | ||
} | ||
}); | ||
} | ||
// Disabled sorting: | ||
if (sortMode === 'none') { | ||
return chunks; | ||
} | ||
// Custom function | ||
if (typeof sortMode === 'function') { | ||
return chunks.sort(sortMode); | ||
} | ||
// Invalid sort mode | ||
throw new Error('"' + sortMode + '" is not a valid chunk sort mode'); | ||
}; | ||
/** | ||
* Return all chunks from the compilation result which match the exclude and include filters | ||
*/ | ||
HtmlWebpackPlugin.prototype.filterChunks = function (webpackStatsJson, includedChunks, excludedChunks) { | ||
var chunks = webpackStatsJson.chunks.filter(function(chunk){ | ||
return webpackStatsJson.chunks.filter(function(chunk){ | ||
var chunkName = chunk.names[0]; | ||
@@ -305,2 +333,6 @@ // This chunk doesn't have a name. This script can't handled it. | ||
} | ||
// Skip if the chunk should be lazy loaded | ||
if (!chunk.initial) { | ||
return false; | ||
} | ||
// Skip if the chunks should be filtered and the given chunk was not added explicity | ||
@@ -317,9 +349,2 @@ if (Array.isArray(includedChunks) && includedChunks.indexOf(chunkName) === -1) { | ||
}); | ||
return chunks.sort(function orderEntryLast(a, b) { | ||
if (a.entry !== b.entry) { | ||
return b.entry ? 1 : -1; | ||
} else { | ||
return b.id - a.id; | ||
} | ||
}); | ||
}; | ||
@@ -326,0 +351,0 @@ |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
var _ = require('lodash'); | ||
@@ -5,3 +7,2 @@ var loaderUtils = require('loader-utils'); | ||
module.exports = function (source) { | ||
'use strict'; | ||
if (this.cacheable) { | ||
@@ -8,0 +9,0 @@ this.cacheable(); |
{ | ||
"name": "html-webpack-plugin", | ||
"version": "2.0.4", | ||
"version": "2.1.0", | ||
"description": "Simplifies creation of HTML files to serve your webpack bundles", | ||
@@ -33,23 +33,24 @@ "main": "index.js", | ||
"devDependencies": { | ||
"appcache-webpack-plugin": "^0.2.0", | ||
"css-loader": "^0.15.4", | ||
"extract-text-webpack-plugin": "^0.8.2", | ||
"appcache-webpack-plugin": "^1.2.1", | ||
"css-loader": "^0.23.0", | ||
"es6-promise": "^3.0.2", | ||
"extract-text-webpack-plugin": "^0.9.1", | ||
"file-loader": "^0.8.4", | ||
"html-loader": "^0.3.0", | ||
"jade-loader": "^0.7.1", | ||
"jade-loader": "^0.8.0", | ||
"jasmine-node": "^1.14.5", | ||
"jshint": "^2.8.0", | ||
"rimraf": "^2.4.1", | ||
"style-loader": "^0.12.3", | ||
"underscore-template-loader": "^0.5.1", | ||
"jshint": "^2.9.1-rc1", | ||
"rimraf": "^2.4.4", | ||
"style-loader": "^0.13.0", | ||
"underscore-template-loader": "^0.5.2", | ||
"url-loader": "^0.5.6", | ||
"webpack": "^1.10.1" | ||
"webpack": "^1.12.8" | ||
}, | ||
"dependencies": { | ||
"loader-utils": "^0.2.10", | ||
"loader-utils": "^0.2.11", | ||
"syntax-error": "^1.1.4", | ||
"bluebird": "^2.9.34", | ||
"html-minifier": "^0.7.2", | ||
"lodash": "^3.10.0" | ||
"bluebird": "^3.0.5", | ||
"html-minifier": "^1.0.0", | ||
"lodash": "^3.10.1" | ||
} | ||
} |
@@ -72,2 +72,3 @@ HTML Webpack Plugin | ||
- `chunks`: Allows you to add only some chunks (e.g. only the unit-test chunk) | ||
- `chunksSortMode`: Allows to controll how chunks should be sorted before they are included to the html. Allowed values: 'none' | 'default' | {function} - default: 'auto' | ||
- `excludeChunks`: Allows you to skip some chunks (e.g. don't add the unit-test chunk) | ||
@@ -74,0 +75,0 @@ |
474
266
26906
14
5
+ Addedalign-text@0.1.4(transitive)
+ Addedbluebird@3.7.2(transitive)
+ Addedcenter-align@0.1.3(transitive)
+ Addedclean-css@3.4.28(transitive)
+ Addedcliui@2.1.0(transitive)
+ Addedcommander@2.8.12.9.0(transitive)
+ Addedconcat-stream@1.5.2(transitive)
+ Addedgraceful-readlink@1.0.1(transitive)
+ Addedhe@1.0.0(transitive)
+ Addedhtml-minifier@1.5.0(transitive)
+ Addedis-buffer@1.1.6(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedkind-of@3.2.2(transitive)
+ Addedlazy-cache@1.0.4(transitive)
+ Addedlongest@1.0.1(transitive)
+ Addedncname@1.0.0(transitive)
+ Addedprocess-nextick-args@1.0.7(transitive)
+ Addedreadable-stream@2.0.6(transitive)
+ Addedrepeat-string@1.6.1(transitive)
+ Addedright-align@0.1.3(transitive)
+ Addedsource-map@0.4.40.5.7(transitive)
+ Addeduglify-js@2.6.4(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedxml-char-classes@1.0.0(transitive)
+ Addedyargs@3.10.0(transitive)
- Removedbluebird@2.11.0(transitive)
- Removedclean-css@3.1.9(transitive)
- Removedcli@0.6.6(transitive)
- Removedcommander@2.6.0(transitive)
- Removedconcat-stream@1.4.11(transitive)
- Removedexit@0.1.2(transitive)
- Removedglob@3.2.11(transitive)
- Removedhtml-minifier@0.7.2(transitive)
- Removedisarray@0.0.1(transitive)
- Removedlru-cache@2.7.3(transitive)
- Removedminimatch@0.3.0(transitive)
- Removedreadable-stream@1.1.14(transitive)
- Removedsigmund@1.0.1(transitive)
- Removedsource-map@0.1.340.1.43(transitive)
- Removeduglify-js@2.4.24(transitive)
- Removedyargs@3.5.4(transitive)
Updatedbluebird@^3.0.5
Updatedhtml-minifier@^1.0.0
Updatedloader-utils@^0.2.11
Updatedlodash@^3.10.1