Skip to content

Commit 36b8c9b

Browse files
Charles Lydinghansl
Charles Lyding
authored andcommitted
fix(@angular/cli): allow the use of a base-href with scheme
1 parent 7cdf56b commit 36b8c9b

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

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

+4
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
5656
if (deployUrl.match(/:\/\//)) {
5757
// If deployUrl contains a scheme, ignore baseHref use deployUrl as is.
5858
return `${deployUrl.replace(/\/$/, '')}${URL}`;
59+
} else if (baseHref.match(/:\/\//)) {
60+
// If baseHref contains a scheme, include it as is.
61+
return baseHref.replace(/\/$/, '') +
62+
`/${deployUrl}/${URL}`.replace(/\/\/+/g, '/');
5963
} else {
6064
// Join together base-href, deploy-url and the original URL.
6165
// Also dedupe multiple slashes into single ones.

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

+15-1
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,27 @@ 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-
// Check urls with scheme are used as is.
50+
// Check urls with deploy-url scheme are used as is.
5151
.then(() => ng('build', '--base-href=/base/', '--deploy-url=http://deploy.url/',
5252
'--extract-css'))
5353
.then(() => expectFileToMatch('dist/styles.bundle.css',
5454
/url\(\'http:\/\/deploy\.url\/assets\/global-img-absolute\.svg\'\)/))
5555
.then(() => expectFileToMatch('dist/main.bundle.js',
5656
/url\(\'http:\/\/deploy\.url\/assets\/component-img-absolute\.svg\'\)/))
57+
// Check urls with base-href scheme are used as is (with deploy-url).
58+
.then(() => ng('build', '--base-href=http://base.url/', '--deploy-url=deploy/',
59+
'--extract-css'))
60+
.then(() => expectFileToMatch('dist/styles.bundle.css',
61+
/url\(\'http:\/\/base\.url\/deploy\/assets\/global-img-absolute\.svg\'\)/))
62+
.then(() => expectFileToMatch('dist/main.bundle.js',
63+
/url\(\'http:\/\/base\.url\/deploy\/assets\/component-img-absolute\.svg\'\)/))
64+
// Check urls with deploy-url and base-href scheme only use deploy-url.
65+
.then(() => ng('build', '--base-href=http://base.url/', '--deploy-url=http://deploy.url/',
66+
'--extract-css'))
67+
.then(() => expectFileToMatch('dist/styles.bundle.css',
68+
/url\(\'http:\/\/deploy\.url\/assets\/global-img-absolute\.svg\'\)/))
69+
.then(() => expectFileToMatch('dist/main.bundle.js',
70+
/url\(\'http:\/\/deploy\.url\/assets\/component-img-absolute\.svg\'\)/))
5771
// Check with base-href and deploy-url flags.
5872
.then(() => ng('build', '--base-href=/base/', '--deploy-url=deploy/',
5973
'--extract-css', '--aot'))

0 commit comments

Comments
 (0)