diff --git a/README.md b/README.md index 25cbdb0..3e3dae8 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,8 @@ You can pass a hash of configuration options to `HtmlWebpackPlugin`. Allowed values are as follows: - `title`: The title to use for the generated HTML document. +- `filename`: The file to write the HTML to. Defaults to `index.html`. + You can specify a subdirectory here too (eg: `assets/admin.html`). Here's an example webpack config illustrating how to use these options: ```javascript @@ -68,7 +70,8 @@ Here's an example webpack config illustrating how to use these options: }, plugins: [ new HtmlWebpackPlugin({ - title: 'My App' + title: 'My App', + filename 'assets/admin.html' }) ] } diff --git a/index.js b/index.js index ebc0308..0e192bc 100644 --- a/index.js +++ b/index.js @@ -23,8 +23,8 @@ 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'); - compiler.assets['index.html'] = { + var outputFilename = self.options.filename || 'index.html'; + compiler.assets[outputFilename] = { source: function() { return html; }, diff --git a/spec/HtmlWebpackPluginSpec.js b/spec/HtmlWebpackPluginSpec.js index 4739607..33b1a16 100644 --- a/spec/HtmlWebpackPluginSpec.js +++ b/spec/HtmlWebpackPluginSpec.js @@ -6,12 +6,12 @@ var HtmlWebpackPlugin = require('../index.js'); var OUTPUT_DIR = path.join(__dirname, '..', 'dist'); -function testHtmlPlugin(webpackConfig, expectedResults, done) { - var outputHtmlFile = path.join(OUTPUT_DIR, 'index.html'); +function testHtmlPlugin(webpackConfig, expectedResults, done, outputFile) { + outputFile = outputFile || 'index.html'; webpack(webpackConfig, function(err, stats) { expect(err).toBeFalsy(); expect(stats.hasErrors()).toBe(false); - var htmlContent = fs.readFileSync(outputHtmlFile).toString(); + var htmlContent = fs.readFileSync(path.join(OUTPUT_DIR, outputFile)).toString(); for (var i = 0; i < expectedResults.length; i++) { var expectedResult = expectedResults[i]; if (expectedResult instanceof RegExp) { @@ -109,7 +109,7 @@ describe('HtmlWebpackPlugin', function() { entry: path.join(__dirname, 'fixtures', 'index.js'), output: { path: OUTPUT_DIR, - filename: path.join('assets', 'index_bundle.js') + filename: 'assets/index_bundle.js' }, plugins: [new HtmlWebpackPlugin()] }, ['