Skip to content

Commit

Permalink
read publicPath from stats to handle [hash]
Browse files Browse the repository at this point in the history
  • Loading branch information
maloguertin committed Mar 17, 2020
1 parent b55ac5d commit 57ad037
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
5 changes: 4 additions & 1 deletion lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,19 @@ ManifestPlugin.prototype.apply = function(compiler) {

var seed = this.opts.seed || {};

var publicPath = this.opts.publicPath != null ? this.opts.publicPath : compilation.options.output.publicPath;
var stats = compilation.getStats().toJson({
// Disable data generation of everything we don't use
all: false,
// Add asset Information
assets: true,
// Show cached assets (setting this to `false` only shows emitted files)
cachedAssets: true,
// Add publicPath information
publicPath: true,
});

var publicPath = this.opts.publicPath != null ? this.opts.publicPath : stats.publicPath;

var files = compilation.chunks.reduce(function(files, chunk) {
return chunk.files.reduce(function (files, path) {
var name = chunk.name ? chunk.name : null;
Expand Down
25 changes: 22 additions & 3 deletions spec/plugin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,25 @@ describe('ManifestPlugin', function() {
});
});

it('prefixes paths with a public path and handle [hash] from public path', function(done) {
webpackCompile({
context: __dirname,
entry: {
one: './fixtures/file.js',
},
output: {
filename: '[name].js',
publicPath: '/[hash]/app/'
}
}, {}, function(manifest, stats) {
expect(manifest).toEqual({
'one.js': '/' + stats.hash + '/app/one.js'
});

done();
});
});

it('is possible to overrides publicPath', (done) => {
webpackCompile({
context: __dirname,
Expand Down Expand Up @@ -412,11 +431,11 @@ describe('ManifestPlugin', function() {
expect(manifest).toEqual({
'main.js': 'main.js'
});

expect(JSON.parse(stats.compilation.assets['manifest.json'].source())).toEqual({
'main.js': 'main.js'
});

done();
});
});
Expand Down Expand Up @@ -485,7 +504,7 @@ describe('ManifestPlugin', function() {
'wStyles.js': 'wStyles.js',
'wStyles.css': 'wStyles.css'
});

done();
});
});
Expand Down

0 comments on commit 57ad037

Please sign in to comment.