diff --git a/lib/plugin.js b/lib/plugin.js index a897575..8e95c96 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -74,7 +74,6 @@ 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, @@ -82,8 +81,12 @@ ManifestPlugin.prototype.apply = function(compiler) { 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; diff --git a/spec/plugin.spec.js b/spec/plugin.spec.js index 3da0d85..8c756d3 100644 --- a/spec/plugin.spec.js +++ b/spec/plugin.spec.js @@ -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, @@ -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(); }); }); @@ -485,7 +504,7 @@ describe('ManifestPlugin', function() { 'wStyles.js': 'wStyles.js', 'wStyles.css': 'wStyles.css' }); - + done(); }); });