Skip to content

Commit 80c01c5

Browse files
authored
feat: allow publicPath to be overriten (#139)
1 parent 3cda5b3 commit 80c01c5

File tree

3 files changed

+47
-21
lines changed

3 files changed

+47
-21
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,19 @@ module.exports = {
5151
}
5252
```
5353

54-
### `publicPath`
55-
56-
Type: `String`
57-
58-
A path prefix that will be added to values of the manifest.
59-
6054
### `options.fileName`
6155

6256
Type: `String`<br>
6357
Default: `manifest.json`
6458

6559
The manifest filename in your output directory.
6660

61+
### `options.publicPath`
62+
63+
Type: `String`
64+
Default: `output.publicPath`
65+
66+
A path prefix that will be added to values of the manifest.
6767

6868
### `options.basePath`
6969

lib/plugin.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const emitCountMap = new Map();
66

77
function ManifestPlugin(opts) {
88
this.opts = _.assign({
9+
publicPath: null,
910
basePath: '',
1011
fileName: 'manifest.json',
1112
transformExtensions: /^(gz|map)$/i,
@@ -50,7 +51,7 @@ ManifestPlugin.prototype.apply = function(compiler) {
5051
const emitCount = emitCountMap.get(outputName) - 1
5152
emitCountMap.set(outputName, emitCount);
5253

53-
var publicPath = compilation.options.output.publicPath;
54+
var publicPath = this.opts.publicPath != null ? this.opts.publicPath : compilation.options.output.publicPath;
5455
var stats = compilation.getStats().toJson();
5556

5657
var files = compilation.chunks.reduce(function(files, chunk) {

spec/plugin.spec.js

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -153,22 +153,47 @@ describe('ManifestPlugin', function() {
153153
});
154154
});
155155

156-
it('prefixes paths with a public path', function(done) {
157-
webpackCompile({
158-
context: __dirname,
159-
entry: {
160-
one: './fixtures/file.js',
161-
},
162-
output: {
163-
filename: '[name].[hash].js',
164-
publicPath: '/app/'
165-
}
166-
}, {}, function(manifest, stats) {
167-
expect(manifest).toEqual({
168-
'one.js': '/app/one.' + stats.hash + '.js'
156+
describe('publicPath', () => {
157+
it('prefixes paths with a public path', function(done) {
158+
webpackCompile({
159+
context: __dirname,
160+
entry: {
161+
one: './fixtures/file.js',
162+
},
163+
output: {
164+
filename: '[name].[hash].js',
165+
publicPath: '/app/'
166+
}
167+
}, {}, function(manifest, stats) {
168+
expect(manifest).toEqual({
169+
'one.js': '/app/one.' + stats.hash + '.js'
170+
});
171+
172+
done();
169173
});
174+
});
170175

171-
done();
176+
it('is possible to overrides publicPath', (done) => {
177+
webpackCompile({
178+
context: __dirname,
179+
entry: {
180+
one: './fixtures/file.js',
181+
},
182+
output: {
183+
filename: '[name].[hash].js',
184+
publicPath: '/app/'
185+
}
186+
}, {
187+
manifestOptions: {
188+
publicPath: '',
189+
}
190+
}, function(manifest, stats) {
191+
expect(manifest).toEqual({
192+
'one.js': 'one.' + stats.hash + '.js'
193+
});
194+
195+
done();
196+
});
172197
});
173198
});
174199

0 commit comments

Comments
 (0)