Hook webpack 'emit' to allow html to be emitted as an asset
This commit is contained in:
parent
4ea9894058
commit
f44af556d8
12
index.js
12
index.js
|
|
@ -8,7 +8,7 @@ function HtmlWebpackPlugin(options) {
|
|||
|
||||
HtmlWebpackPlugin.prototype.apply = function(compiler) {
|
||||
var self = this;
|
||||
compiler.plugin('after-emit', function(compiler, callback) {
|
||||
compiler.plugin('emit', function(compiler, callback) {
|
||||
var webpackStatsJson = compiler.getStats().toJson();
|
||||
var templateParams = {};
|
||||
templateParams.webpack = webpackStatsJson;
|
||||
|
|
@ -24,7 +24,15 @@ HtmlWebpackPlugin.prototype.apply = function(compiler) {
|
|||
var htmlTemplateContent = fs.readFileSync(templateFile, 'utf8');
|
||||
var html = tmpl(htmlTemplateContent, templateParams);
|
||||
var outputPath = path.join(compiler.options.output.path, 'index.html');
|
||||
this.outputFileSystem.writeFile(outputPath, html, callback);
|
||||
compiler.assets['index.html'] = {
|
||||
source: function() {
|
||||
return html;
|
||||
},
|
||||
size: function() {
|
||||
return html.length;
|
||||
}
|
||||
};
|
||||
callback();
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
document.body.textContent = helloText();
|
||||
document.body.innerHTML = document.body.innerHTML + "<p>index.js</p>";
|
||||
|
|
|
|||
|
|
@ -1,3 +1 @@
|
|||
function helloText() {
|
||||
return "Hello world";
|
||||
}
|
||||
document.body.innerHTML = document.body.innerHTML + "<p>util.js</p>";
|
||||
|
|
|
|||
Loading…
Reference in New Issue