Don’t emit the html for hot-update compilation.

webpack-dev-server@2.0.0-beta seems to be emitting hot update bundles separately from the full bundle. This makes HtmlWebpackPlugin mistake it for the real bundle, and generates a HTML file that looks like this:

```html
<script src="0.8f9c33574d86dd9eab0d.hot-update.js"></scriptt>
```

This commit uses quite a hack to check if the emitted bundle is a hot-update bundle, and skip emitting `index.html` file.
This commit is contained in:
Thai Pangsakulyanont 2016-04-02 16:47:06 +07:00
parent c776cdd586
commit 25fd764e16
1 changed files with 12 additions and 0 deletions

View File

@ -68,6 +68,12 @@ HtmlWebpackPlugin.prototype.apply = function (compiler) {
chunks = self.sortChunks(chunks, self.options.chunksSortMode);
// Get assets
var assets = self.htmlWebpackPluginAssets(compilation, chunks);
// If this is a hot update compilation, move on!
// This solves a problem where an `index.html` file is generated for hot-update js files
// It only happens in Webpack 2, where hot updates are emitted separately before the full bundle
if (self.isHotUpdateCompilation(assets)) {
return callback();
}
// If the template and the assets did not change we don't have to emit the html
var assetJson = JSON.stringify(self.getAssetFiles(assets));
@ -340,6 +346,12 @@ HtmlWebpackPlugin.prototype.filterChunks = function (webpackStatsJson, includedC
});
};
HtmlWebpackPlugin.prototype.isHotUpdateCompilation = function (assets) {
return assets.js.every(function (name) {
return /\.hot-update\.js$/.test(name);
});
};
HtmlWebpackPlugin.prototype.htmlWebpackPluginAssets = function (compilation, chunks) {
var self = this;
var webpackStatsJson = compilation.getStats().toJson();