diff --git a/index.js b/index.js index 0e192bc..b48abd4 100644 --- a/index.js +++ b/index.js @@ -21,18 +21,23 @@ HtmlWebpackPlugin.prototype.apply = function(compiler) { templateFile = path.join(__dirname, 'default_index.html'); } - var htmlTemplateContent = fs.readFileSync(templateFile, 'utf8'); - var html = tmpl(htmlTemplateContent, templateParams); - var outputFilename = self.options.filename || 'index.html'; - compiler.assets[outputFilename] = { - source: function() { - return html; - }, - size: function() { - return html.length; + fs.readFile(templateFile, 'utf8', function(err, htmlTemplateContent) { + if (err) { + compiler.errors.push(new Error('HtmlWebpackPlugin: Unable to read HTML template "' + templateFile + '"')); + } else { + var html = tmpl(htmlTemplateContent, templateParams); + var outputFilename = self.options.filename || 'index.html'; + compiler.assets[outputFilename] = { + source: function() { + return html; + }, + size: function() { + return html.length; + } + }; } - }; - callback(); + callback(); + }); }); }; diff --git a/spec/HtmlWebpackPluginSpec.js b/spec/HtmlWebpackPluginSpec.js index 766d87b..b1f15f1 100644 --- a/spec/HtmlWebpackPluginSpec.js +++ b/spec/HtmlWebpackPluginSpec.js @@ -6,7 +6,7 @@ var HtmlWebpackPlugin = require('../index.js'); var OUTPUT_DIR = path.join(__dirname, '../dist'); -function testHtmlPlugin(webpackConfig, expectedResults, done, outputFile) { +function testHtmlPlugin(webpackConfig, expectedResults, outputFile, done) { outputFile = outputFile || 'index.html'; webpack(webpackConfig, function(err, stats) { expect(err).toBeFalsy(); @@ -37,7 +37,7 @@ describe('HtmlWebpackPlugin', function() { filename: 'index_bundle.js' }, plugins: [new HtmlWebpackPlugin()] - }, ['