Hook webpack 'after-emit' instead of 'done' so it works with webpack middleware

This commit is contained in:
Charles Blaxland 2014-08-13 17:18:31 +10:00
parent 07c60a5ae1
commit 4ea9894058
3 changed files with 10 additions and 5 deletions

View File

@ -8,8 +8,8 @@ function HtmlWebpackPlugin(options) {
HtmlWebpackPlugin.prototype.apply = function(compiler) {
var self = this;
compiler.plugin('done', function(stats) {
var webpackStatsJson = stats.toJson();
compiler.plugin('after-emit', function(compiler, callback) {
var webpackStatsJson = compiler.getStats().toJson();
var templateParams = {};
templateParams.webpack = webpackStatsJson;
templateParams.htmlWebpackPlugin = {};
@ -20,8 +20,11 @@ HtmlWebpackPlugin.prototype.apply = function(compiler) {
if (!templateFile) {
templateFile = path.join(__dirname, 'default_index.html');
}
var htmlTemplateContent = fs.readFileSync(templateFile, 'utf8');
fs.writeFileSync(path.join(compiler.options.output.path, 'index.html'), tmpl(htmlTemplateContent, templateParams));
var html = tmpl(htmlTemplateContent, templateParams);
var outputPath = path.join(compiler.options.output.path, 'index.html');
this.outputFileSystem.writeFile(outputPath, html, callback);
});
};

View File

@ -1,7 +1,7 @@
{
"name": "html-webpack-plugin",
"version": "0.1.0",
"description": "Generates HTML files to serve your webpack bundles",
"version": "0.2.0",
"description": "Simplifies creation of HTML files to serve your webpack bundles",
"main": "index.js",
"scripts": {
"test": "node_modules/.bin/jshint *.js spec && node_modules/.bin/jasmine-node --captureExceptions spec"

View File

@ -113,7 +113,9 @@ describe('HtmlWebpackPlugin', function() {
},
plugins: [new HtmlWebpackPlugin()]
}, ['<script src="assets/index_bundle.js"'], done);
});
it('handles subdirectories in the webpack output bundles along with a public path', function(done) {
testHtmlPlugin({
entry: path.join(__dirname, 'fixtures', 'index.js'),
output: {