From fd0ca3e15692dbca9e8fab73d0a26f6764b252e9 Mon Sep 17 00:00:00 2001 From: Filipe Silva Date: Fri, 10 Mar 2017 18:22:22 +0000 Subject: [PATCH] fix(@angular/cli): don't break deployUrl with scheme Fix #5254 --- .../@angular/cli/models/webpack-configs/styles.ts | 12 +++++++++--- tests/e2e/tests/build/css-urls.ts | 9 ++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/@angular/cli/models/webpack-configs/styles.ts b/packages/@angular/cli/models/webpack-configs/styles.ts index f3666c8b7545..bba4a42b3b6e 100644 --- a/packages/@angular/cli/models/webpack-configs/styles.ts +++ b/packages/@angular/cli/models/webpack-configs/styles.ts @@ -52,9 +52,15 @@ export function getStylesConfig(wco: WebpackConfigOptions) { if (!URL.startsWith('/') || URL.startsWith('//')) { return URL; } - // Join together base-href, deploy-url and the original URL. - // Also dedupe multiple slashes into single ones. - return `/${baseHref || ''}/${deployUrl || ''}/${URL}`.replace(/\/\/+/g, '/'); + + if (deployUrl.match(/:\/\//)) { + // If deployUrl contains a scheme, ignore baseHref use deployUrl as is. + return `${deployUrl.replace(/\/$/, '')}${URL}`; + } else { + // Join together base-href, deploy-url and the original URL. + // Also dedupe multiple slashes into single ones. + return `/${baseHref || ''}/${deployUrl || ''}/${URL}`.replace(/\/\/+/g, '/'); + } } }; const urlPlugin = postcssUrl(postcssUrlOptions); diff --git a/tests/e2e/tests/build/css-urls.ts b/tests/e2e/tests/build/css-urls.ts index 4248769cfc48..19940083eaec 100644 --- a/tests/e2e/tests/build/css-urls.ts +++ b/tests/e2e/tests/build/css-urls.ts @@ -47,7 +47,14 @@ export default function () { .then(() => expectToFail(() => expectFileToExist('dist/component-img-absolute.svg'))) .then(() => expectFileMatchToExist('./dist', /global-img-relative\.[0-9a-f]{20}\.svg/)) .then(() => expectFileMatchToExist('./dist', /component-img-relative\.[0-9a-f]{20}\.svg/)) - // Also check with base-href and deploy-url flags. + // Check urls with scheme are used as is. + .then(() => ng('build', '--base-href=/base/', '--deploy-url=http://deploy.url/', + '--extract-css')) + .then(() => expectFileToMatch('dist/styles.bundle.css', + /url\(http:\/\/deploy.url\/global-img-relative\.svg\)/)) + .then(() => expectFileToMatch('dist/main.bundle.js', + /url\(http:\/\/deploy.url\/component-img-relative\.svg\)/)) + // Check with base-href and deploy-url flags. .then(() => ng('build', '--base-href=/base/', '--deploy-url=deploy/', '--extract-css', '--aot')) .then(() => expectFileToMatch('dist/styles.bundle.css',