Skip to content

Commit

Permalink
fix issue in generated public path of manifest.json
Browse files Browse the repository at this point in the history
- when using devServer and absolute URL for publicPath
- also add test case
  • Loading branch information
robertfausk authored and weaverryan committed Jul 21, 2017
1 parent eb5565b commit e206a12
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/WebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ class WebpackConfig {
* @returns {string}
*/
getRealPublicPath() {
// if we're using webpack-dev-server, use it & add the publicPath
if (this.useDevServer()) {
// if we're using webpack-dev-server and have no absolute url, use it & add the publicPath
if (this.useDevServer() && !this.publicPath.includes('://')) {
// avoid 2 middle slashes
return this.runtimeConfig.devServerUrl.replace(/\/$/,'') + this.publicPath;
}
Expand Down
17 changes: 17 additions & 0 deletions test/config-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,23 @@ describe('The config-generator function', () => {
expect(actualConfig.devServer).to.be.undefined;
});

it('devServer and an absolute URL as publicPath', () => {
const config = createConfig();
config.runtimeConfig.useDevServer = true;
config.runtimeConfig.devServerUrl = 'http://localhost:8080/';
config.outputPath = isWindows ? 'C:\\tmp\\public' : '/tmp/public';
config.setManifestKeyPrefix('public');
config.setPublicPath('https://cdn.example.com');
config.addEntry('main', './main');

const actualConfig = configGenerator(config);
expect(actualConfig.output.publicPath).to.equal('https://cdn.example.com/');
expect(actualConfig.devServer).to.not.be.undefined;

const manifestPlugin = findPlugin(ManifestPlugin, actualConfig.plugins);
expect(manifestPlugin.opts.publicPath).to.equal('https://cdn.example.com/');
});

it('devServer no hot mode', () => {
const config = createConfig();
config.runtimeConfig.useDevServer = true;
Expand Down

0 comments on commit e206a12

Please sign in to comment.