Support placing templates in subfolders
This commit is contained in:
parent
266d8e2325
commit
55b530ba3f
10
index.js
10
index.js
|
|
@ -171,7 +171,15 @@ HtmlWebpackPlugin.prototype.addFileToAssets = function(compilation, filename) {
|
|||
|
||||
HtmlWebpackPlugin.prototype.htmlWebpackPluginAssets = function(compilation, webpackStatsJson, includedChunks, excludedChunks) {
|
||||
var self = this;
|
||||
var publicPath = compilation.options.output.publicPath || '';
|
||||
|
||||
// Use the configured public path or build a relative path
|
||||
var publicPath = typeof compilation.options.output.publicPath !== 'undefined' ?
|
||||
compilation.options.output.publicPath :
|
||||
path.relative(path.dirname(self.options.filename), '.');
|
||||
|
||||
if (publicPath.length && publicPath.substr(-1, 1) !== '/') {
|
||||
publicPath += '/';
|
||||
}
|
||||
|
||||
var assets = {
|
||||
// Will contain all js & css files by chunk
|
||||
|
|
|
|||
|
|
@ -446,7 +446,7 @@ describe('HtmlWebpackPlugin', function() {
|
|||
}, ['<script src="index_bundle.js"'], 'test.html', done);
|
||||
});
|
||||
|
||||
it('allows you to configure the output filename with a path', function(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'),
|
||||
output: {
|
||||
|
|
@ -454,7 +454,18 @@ describe('HtmlWebpackPlugin', function() {
|
|||
filename: 'index_bundle.js'
|
||||
},
|
||||
plugins: [new HtmlWebpackPlugin({filename: 'assets/test.html'})]
|
||||
}, ['<script src="index_bundle.js"'], 'assets/test.html', done);
|
||||
}, ['<script src="../index_bundle.js"'], 'assets/test.html', done);
|
||||
});
|
||||
|
||||
it('will try to use a relative name if the filename and the script are in a subdirectory', function(done) {
|
||||
testHtmlPlugin({
|
||||
entry: path.join(__dirname, 'fixtures/index.js'),
|
||||
output: {
|
||||
path: OUTPUT_DIR,
|
||||
filename: 'assets/index_bundle.js'
|
||||
},
|
||||
plugins: [new HtmlWebpackPlugin({filename: 'assets/demo/test.html'})]
|
||||
}, ['<script src="../../assets/index_bundle.js"'], 'assets/demo/test.html', done);
|
||||
});
|
||||
|
||||
it('allows you write multiple HTML files', function(done) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue