support absolute filenames

This commit is contained in:
Evan You 2016-03-23 03:08:46 -04:00
parent 9066ad2ad3
commit e4e9555209
2 changed files with 20 additions and 0 deletions

View File

@ -35,6 +35,13 @@ HtmlWebpackPlugin.prototype.apply = function (compiler) {
this.options.template = this.getFullTemplatePath(this.options.template, compiler.context);
// convert absolute filename into relative so that webpack can
// generate it at correct location
var filename = this.options.filename;
if (path.resolve(filename) === path.normalize(filename)) {
this.options.filename = path.relative(compiler.options.output.path, filename);
}
compiler.plugin('make', function (compilation, callback) {
// Compile the template (queued)
compilationPromise = childCompiler.compileTemplate(self.options.template, compiler.context, self.options.filename, compilation)

View File

@ -571,6 +571,19 @@ describe('HtmlWebpackPlugin', function () {
}, ['<script src="index_bundle.js"'], 'test.html', done);
});
it('allows you to use an absolute output filename', function (done) {
testHtmlPlugin({
entry: path.join(__dirname, 'fixtures/index.js'),
output: {
path: OUTPUT_DIR,
filename: 'index_bundle.js'
},
plugins: [new HtmlWebpackPlugin({
filename: path.resolve(OUTPUT_DIR, 'test.html')
})]
}, ['<script src="index_bundle.js"'], 'test.html', done);
});
it('will try to use a relative name if the filename is in a subdirectory', function (done) {
testHtmlPlugin({
entry: path.join(__dirname, 'fixtures/index.js'),