Skip to content

Commit

Permalink
FIX missing [hash] interpolation in publicPath
Browse files Browse the repository at this point in the history
Webpack gives the possibility to use the build [hash] in
output.publicPath option:
https://webpack.github.io/docs/long-term-caching.html

However HtmlWebpackPlugin is reading directly the raw option, preventing the
user to use this option when using it.
  • Loading branch information
thomasguillory committed Oct 2, 2015
1 parent 2733718 commit 41a255a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ HtmlWebpackPlugin.prototype.htmlWebpackPluginAssets = function(compilation, webp

// Use the configured public path or build a relative path
var publicPath = typeof compilation.options.output.publicPath !== 'undefined' ?
compilation.options.output.publicPath :
compilation.mainTemplate.getPublicPath({hash: webpackStatsJson.hash}) :
path.relative(path.dirname(self.options.filename), '.');

if (publicPath.length && publicPath.substr(-1, 1) !== '/') {
Expand Down
12 changes: 12 additions & 0 deletions spec/HtmlWebpackPluginSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,18 @@ describe('HtmlWebpackPlugin', function() {
}, [/<script src="index_bundle_[0-9a-f]+\.js/], null, done);
});

it('handles hashes in publicPath', function(done) {
testHtmlPlugin({
entry: path.join(__dirname, 'fixtures/index.js'),
output: {
path: OUTPUT_DIR,
filename: 'index_bundle.js',
publicPath: 'assets/[hash]/'
},
plugins: [new HtmlWebpackPlugin()]
}, [/<script src="assets\/[0-9a-f]+\/index_bundle\.js/], null, done);
});

it('allows to append hashes to the assets', function(done) {
testHtmlPlugin({
entry: path.join(__dirname, 'fixtures/index.js'),
Expand Down

2 comments on commit 41a255a

@sandeep45
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@sandeep45
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thomasguillory I dont see this commit in master. I cant figure out why. Could you assist?

Please sign in to comment.