From 23bc582f2eb283af9b9aba9569b566a485dda238 Mon Sep 17 00:00:00 2001 From: Hans Larsen Date: Mon, 11 Sep 2017 10:32:49 -0700 Subject: [PATCH] fix(@angular/cli): publicPath should not be path.join Using path.join removes duplicated slashes, like in https://. This code is the correct version used in the original html-webpack-plugin. Fixes #7650 --- .../cli/plugins/insert-concat-assets-webpack-plugin.ts | 10 ++++++++-- tests/e2e/tests/build/deploy-url.ts | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/@angular/cli/plugins/insert-concat-assets-webpack-plugin.ts b/packages/@angular/cli/plugins/insert-concat-assets-webpack-plugin.ts index 45ff96e63d84..039c0afafd00 100644 --- a/packages/@angular/cli/plugins/insert-concat-assets-webpack-plugin.ts +++ b/packages/@angular/cli/plugins/insert-concat-assets-webpack-plugin.ts @@ -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. @@ -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; diff --git a/tests/e2e/tests/build/deploy-url.ts b/tests/e2e/tests/build/deploy-url.ts index 83d66b5ba5a2..5882d2c8e5ba 100644 --- a/tests/e2e/tests/build/deploy-url.ts +++ b/tests/e2e/tests/build/deploy-url.ts @@ -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];