Skip to content

Commit 91f3f5b

Browse files
clydinBrocco
authored andcommitted
fix(@angular/cli): account for root relative URLs in CSS assets
1 parent 330079c commit 91f3f5b

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
6363
// Only convert root relative URLs, which CSS-Loader won't process into require().
6464
filter: ({ url }: { url: string }) => url.startsWith('/') && !url.startsWith('//'),
6565
url: ({ url }: { url: string }) => {
66-
if (deployUrl.match(/:\/\//)) {
67-
// If deployUrl contains a scheme, ignore baseHref use deployUrl as is.
66+
if (deployUrl.match(/:\/\//) || deployUrl.startsWith('/')) {
67+
// If deployUrl is absolute or root relative, ignore baseHref & use deployUrl as is.
6868
return `${deployUrl.replace(/\/$/, '')}${url}`;
6969
} else if (baseHref.match(/:\/\//)) {
7070
// If baseHref contains a scheme, include it as is.

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

+23-1
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,27 @@ export default function () {
7979
.then(() => expectFileToMatch('dist/main.bundle.js',
8080
'/base/deploy/assets/component-img-absolute.svg'))
8181
.then(() => expectFileToMatch('dist/main.bundle.js',
82-
/deploy\/component-img-relative\.[0-9a-f]{20}\.png/));
82+
/deploy\/component-img-relative\.[0-9a-f]{20}\.png/))
83+
// Check with identical base-href and deploy-url flags.
84+
.then(() => ng('build', '--base-href=/base/', '--deploy-url=/base/',
85+
'--extract-css', '--aot'))
86+
.then(() => expectFileToMatch('dist/styles.bundle.css',
87+
'/base/assets/global-img-absolute.svg'))
88+
.then(() => expectFileToMatch('dist/styles.bundle.css',
89+
/global-img-relative\.[0-9a-f]{20}\.png/))
90+
.then(() => expectFileToMatch('dist/main.bundle.js',
91+
'/base/assets/component-img-absolute.svg'))
92+
.then(() => expectFileToMatch('dist/main.bundle.js',
93+
/\/base\/component-img-relative\.[0-9a-f]{20}\.png/))
94+
// Check with only base-href flag.
95+
.then(() => ng('build', '--base-href=/base/',
96+
'--extract-css', '--aot'))
97+
.then(() => expectFileToMatch('dist/styles.bundle.css',
98+
'/base/assets/global-img-absolute.svg'))
99+
.then(() => expectFileToMatch('dist/styles.bundle.css',
100+
/global-img-relative\.[0-9a-f]{20}\.png/))
101+
.then(() => expectFileToMatch('dist/main.bundle.js',
102+
'/base/assets/component-img-absolute.svg'))
103+
.then(() => expectFileToMatch('dist/main.bundle.js',
104+
/component-img-relative\.[0-9a-f]{20}\.png/));
83105
}

0 commit comments

Comments
 (0)