From 55b530ba3f9b6ef989fecc55b0636c1c507f95d8 Mon Sep 17 00:00:00 2001 From: Jan Nicklas Date: Mon, 29 Jun 2015 15:57:18 +0200 Subject: [PATCH] Support placing templates in subfolders --- index.js | 10 +++++++++- spec/HtmlWebpackPluginSpec.js | 15 +++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 22604ce..f411ddf 100644 --- a/index.js +++ b/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 diff --git a/spec/HtmlWebpackPluginSpec.js b/spec/HtmlWebpackPluginSpec.js index 43db916..a8bde34 100644 --- a/spec/HtmlWebpackPluginSpec.js +++ b/spec/HtmlWebpackPluginSpec.js @@ -446,7 +446,7 @@ describe('HtmlWebpackPlugin', function() { }, ['