Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build public path with correct hash value #249

Merged
merged 2 commits into from
Mar 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ HtmlWebpackPlugin.prototype.htmlWebpackPluginAssets = function (compilation, chu

// 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), '.').split(path.sep).join('/');

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 @@ -355,6 +355,18 @@ describe('HtmlWebpackPlugin', function () {
}, [/<script src="index_bundle_[0-9a-f]+\.js"*/], null, done);
});

it('handles hashes in the directory which has the bundle file', function (done) {
testHtmlPlugin({
entry: path.join(__dirname, 'fixtures/index.js'),
output: {
path: path.join(__dirname, '../dist'),
publicPath: '/dist/[hash]/',
filename: 'index_bundle_[hash].js'
},
plugins: [new HtmlWebpackPlugin()]
}, [/<script src="\/dist\/[0-9a-f]+\/index_bundle_[0-9a-f]+\.js"*/], null, done);
});

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