-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(@angular/cli): correctly compose absolute urls
Fixing component css in #4667 uncovered errors in CSS url processing. This PR correctly composes absolute urls when using `--base-href` and/or `--deploy-url`. Fix #4778 Fix #4782
- Loading branch information
1 parent
d2bef98
commit 3fadf6a
Showing
5 changed files
with
78 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { ng } from '../../utils/process'; | ||
import { expectFileToMatch, writeMultipleFiles } from '../../utils/fs'; | ||
import { stripIndents } from 'common-tags'; | ||
|
||
|
||
export default function () { | ||
return Promise.resolve() | ||
// Verify absolute/relative paths in global/component css. | ||
.then(() => writeMultipleFiles({ | ||
'src/styles.css': ` | ||
h1 { background: url('/assets/img-absolute.svg'); } | ||
h2 { background: url('./assets/img-relative.svg'); } | ||
`, | ||
'src/app/app.component.css': ` | ||
h3 { background: url('/assets/img-absolute.svg'); } | ||
h4 { background: url('../assets/img-relative.svg'); } | ||
`, | ||
// Using SVGs because they are loaded via file-loader and thus never inlined. | ||
'src/assets/img-absolute.svg': stripIndents` | ||
<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg"> | ||
<circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" /> | ||
</svg> | ||
`, | ||
'src/assets/img-relative.svg': stripIndents` | ||
<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg"> | ||
<circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" /> | ||
</svg> | ||
`})) | ||
.then(() => ng('build', '--extract-css')) | ||
.then(() => expectFileToMatch('dist/styles.bundle.css', `url\('\/assets\/img-absolute\.svg'\)`)) | ||
.then(() => expectFileToMatch('dist/styles.bundle.css', 'url\(img-relative.svg\)')) | ||
.then(() => expectFileToMatch('dist/main.bundle.js', `url\('\/assets\/img-absolute\.svg'\)`)) | ||
.then(() => expectFileToMatch('dist/main.bundle.js', 'background: url\(" \+ __webpack_require')) | ||
// Also check with base-href and deploy-url flags. | ||
.then(() => ng('build', '--base-href=/base/', '--deploy-url=/deploy/', '--extract-css')) | ||
.then(() => expectFileToMatch('dist/styles.bundle.css', | ||
`url\('\/base\/deploy\/assets\/img-absolute\.svg'\)`)) | ||
.then(() => expectFileToMatch('dist/styles.bundle.css', 'url\(img-relative.svg\)')) | ||
.then(() => expectFileToMatch('dist/main.bundle.js', | ||
`url\('\/base\/deploy\/assets\/img-absolute\.svg'\)`)) | ||
.then(() => expectFileToMatch('dist/main.bundle.js', | ||
'background: url\(" \+ __webpack_require')); | ||
} |