Skip to content

Commit

Permalink
feat: support empty public path
Browse files Browse the repository at this point in the history
  • Loading branch information
prsnca authored and shirotech committed Jun 11, 2019
1 parent 334b9cc commit 9bb9c7c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
18 changes: 11 additions & 7 deletions module.js
Expand Up @@ -28,16 +28,20 @@ class WebpackCdnPlugin {

apply(compiler) {
const { output } = compiler.options;
output.publicPath = output.publicPath || '/';
if (this.prefix === empty) {
output.publicPath = empty;
} else {
output.publicPath = output.publicPath || '/';

if (output.publicPath.slice(-1) !== slash) {
output.publicPath += slash;
}
if (output.publicPath.slice(-1) !== slash) {
output.publicPath += slash;
}

this.prefix = this.prod ? empty : this.prefix || output.publicPath;
this.prefix = this.prod ? empty : this.prefix || output.publicPath;

if (!this.prod && this.prefix.slice(-1) !== slash) {
this.prefix += slash;
if (!this.prod && this.prefix.slice(-1) !== slash) {
this.prefix += slash;
}
}

const getArgs = [this.url, this.prefix, this.prod, output.publicPath];
Expand Down
22 changes: 21 additions & 1 deletion spec/webpack.spec.js
Expand Up @@ -143,7 +143,7 @@ function getConfig({
crossOrigin,
};

if (publicPath) {
if (publicPath !== undefined) {
options.publicPath = publicPath;
}

Expand Down Expand Up @@ -382,6 +382,26 @@ describe('Webpack Integration', () => {
});
});

describe('When `publicPath` is empty', () => {
beforeAll((done) => {
runWebpack(done, getConfig({ prod: false, publicPath: '' }));
});

it('should output the right assets (css)', () => {
expect(cssAssets).toEqual(['local.css', 'nyc/style.css', 'jasmine/style.css']);
});

it('should output the right assets (js)', () => {
expect(jsAssets).toEqual([
'local.js',
'jasmine-spec-reporter/index.js',
'nyc/index.js',
'jasmine/lib/jasmine.js',
'app.js',
]);
});
});

describe('When `publicPath` is set', () => {
beforeAll((done) => {
runWebpack(done, getConfig({ prod: false }));
Expand Down

0 comments on commit 9bb9c7c

Please sign in to comment.