Skip to content

Commit 9077f12

Browse files
committed
fix(@angular/cli): don't break deployUrl with scheme
Fix angular#5254
1 parent 5b1668f commit 9077f12

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

packages/@angular/cli/models/webpack-configs/styles.ts

+11-5
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,23 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
4444
const cssnanoPlugin = cssnano({ safe: true, autoprefixer: false });
4545

4646
// Convert absolute resource URLs to account for base-href and deploy-url.
47-
const baseHref = wco.buildOptions.baseHref;
48-
const deployUrl = wco.buildOptions.deployUrl;
47+
const baseHref = wco.buildOptions.baseHref || '';
48+
const deployUrl = wco.buildOptions.deployUrl || '';
4949
const postcssUrlOptions = {
5050
url: (URL: string) => {
5151
// Only convert root relative URLs, which CSS-Loader won't process into require().
5252
if (!URL.startsWith('/') || URL.startsWith('//')) {
5353
return URL;
5454
}
55-
// Join together base-href, deploy-url and the original URL.
56-
// Also dedupe multiple slashes into single ones.
57-
return `/${baseHref || ''}/${deployUrl || ''}/${URL}`.replace(/\/\/+/g, '/');
55+
56+
if (deployUrl.match(/:\/\//)) {
57+
// If deployUrl contains a scheme, ignore baseHref use deployUrl as is.
58+
return `${deployUrl.replace(/\/$/, '')}${URL}`;
59+
} else {
60+
// Join together base-href, deploy-url and the original URL.
61+
// Also dedupe multiple slashes into single ones.
62+
return `/${baseHref}/${deployUrl}/${URL}`.replace(/\/\/+/g, '/');
63+
}
5864
}
5965
};
6066
const urlPlugin = postcssUrl(postcssUrlOptions);

tests/e2e/tests/build/css-urls.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,14 @@ export default function () {
4747
.then(() => expectToFail(() => expectFileToExist('dist/component-img-absolute.svg')))
4848
.then(() => expectFileMatchToExist('./dist', /global-img-relative\.[0-9a-f]{20}\.svg/))
4949
.then(() => expectFileMatchToExist('./dist', /component-img-relative\.[0-9a-f]{20}\.svg/))
50-
// Also check with base-href and deploy-url flags.
50+
// Check urls with scheme are used as is.
51+
.then(() => ng('build', '--base-href=/base/', '--deploy-url=http://deploy.url/',
52+
'--extract-css'))
53+
.then(() => expectFileToMatch('dist/styles.bundle.css',
54+
/url\(http:\/\/deploy\.url\/assets\/global-img-absolute\.svg\)/))
55+
.then(() => expectFileToMatch('dist/main.bundle.js',
56+
/url\(http:\/\/deploy\.url\/assets\/component-img-absolute\.svg\)/))
57+
// Check with base-href and deploy-url flags.
5158
.then(() => ng('build', '--base-href=/base/', '--deploy-url=deploy/',
5259
'--extract-css', '--aot'))
5360
.then(() => expectFileToMatch('dist/styles.bundle.css',

0 commit comments

Comments
 (0)