Skip to content
Permalink
Browse files

feat: support empty public path

  • Loading branch information...
prsnca authored and shirotech committed Jun 11, 2019
1 parent 334b9cc commit 9bb9c7c8a8521a8843d028b65d9c5d9d7f951923
Showing with 32 additions and 8 deletions.
  1. +11 −7 module.js
  2. +21 −1 spec/webpack.spec.js
@@ -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];
@@ -143,7 +143,7 @@ function getConfig({
crossOrigin,
};

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

@@ -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 }));

0 comments on commit 9bb9c7c

Please sign in to comment.
You can’t perform that action at this time.