support absolute filenames
This commit is contained in:
parent
9066ad2ad3
commit
e4e9555209
7
index.js
7
index.js
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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'),
|
||||
|
|
|
|||
Loading…
Reference in New Issue