html-webpack-plugin
Advanced tools
Comparing version
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
5.33%266
0.38%26906
-4.81%14
7.69%5
-28.57%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated
Updated
Updated
Updated