Skip to content

Commit

Permalink
fix(@angular/cli): publicPath should not be path.join
Browse files Browse the repository at this point in the history
Using path.join removes duplicated slashes, like in https://. This code
is the correct version used in the original html-webpack-plugin.

Fixes #7650
  • Loading branch information
hansl committed Sep 13, 2017
1 parent 642f6ba commit 90fddc5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Add assets from `ConcatPlugin` to index.html.
import * as path from 'path';


export class InsertConcatAssetsWebpackPlugin {
// Priority list of where to insert asset.
Expand All @@ -24,7 +24,13 @@ export class InsertConcatAssetsWebpackPlugin {
throw new Error(`Cannot find file for ${entryName} script.`);
}

return path.join(htmlPluginData.assets.publicPath, fileName);
if (htmlPluginData.assets.publicPath) {
if (htmlPluginData.assets.publicPath.endsWith('/')) {
return htmlPluginData.assets.publicPath + fileName;
}
return htmlPluginData.assets.publicPath + '/' + fileName;
}
return fileName;
});

let insertAt = 0;
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/tests/build/deploy-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export default function () {
.then(() => expectFileToMatch('dist/index.html', 'deployUrl/main.bundle.js'))
// verify --deploy-url isn't applied to extracted css urls
.then(() => expectFileToMatch('dist/styles.bundle.css', /url\(more\.[0-9a-f]{20}\.svg\)/))
.then(() => ng('build', '--deploy-url=http://example.com/some/path/', '--extract-css'))
.then(() => expectFileToMatch('dist/index.html', 'http://example.com/some/path/main.bundle.js'))
// verify option also works in config
.then(() => updateJsonFile('.angular-cli.json', configJson => {
const app = configJson['apps'][0];
Expand Down

0 comments on commit 90fddc5

Please sign in to comment.