Skip to content

Commit

Permalink
feat: allow publicPath to be overriten (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
mastilver authored Apr 8, 2018
1 parent 3cda5b3 commit 80c01c5
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 21 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ module.exports = {
}
```

### `publicPath`

Type: `String`

A path prefix that will be added to values of the manifest.

### `options.fileName`

Type: `String`<br>
Default: `manifest.json`

The manifest filename in your output directory.

### `options.publicPath`

Type: `String`
Default: `output.publicPath`

A path prefix that will be added to values of the manifest.

### `options.basePath`

Expand Down
3 changes: 2 additions & 1 deletion lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const emitCountMap = new Map();

function ManifestPlugin(opts) {
this.opts = _.assign({
publicPath: null,
basePath: '',
fileName: 'manifest.json',
transformExtensions: /^(gz|map)$/i,
Expand Down Expand Up @@ -50,7 +51,7 @@ ManifestPlugin.prototype.apply = function(compiler) {
const emitCount = emitCountMap.get(outputName) - 1
emitCountMap.set(outputName, emitCount);

var publicPath = compilation.options.output.publicPath;
var publicPath = this.opts.publicPath != null ? this.opts.publicPath : compilation.options.output.publicPath;
var stats = compilation.getStats().toJson();

var files = compilation.chunks.reduce(function(files, chunk) {
Expand Down
53 changes: 39 additions & 14 deletions spec/plugin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,22 +153,47 @@ describe('ManifestPlugin', function() {
});
});

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

done();
});
});

done();
it('is possible to overrides publicPath', (done) => {
webpackCompile({
context: __dirname,
entry: {
one: './fixtures/file.js',
},
output: {
filename: '[name].[hash].js',
publicPath: '/app/'
}
}, {
manifestOptions: {
publicPath: '',
}
}, function(manifest, stats) {
expect(manifest).toEqual({
'one.js': 'one.' + stats.hash + '.js'
});

done();
});
});
});

Expand Down

0 comments on commit 80c01c5

Please sign in to comment.