Skip to content

Commit 9caa7ca

Browse files
clydinfilipesilva
authored andcommitted
fix(@angular/cli): support inlining stylesheet resource tilde paths
1 parent 64b4b03 commit 9caa7ca

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
4646

4747
const postcssPluginCreator = function() {
4848
return [
49+
postcssUrl({
50+
filter: ({ url }: { url: string }) => url.startsWith('~'),
51+
url: ({ url }: { url: string }) => path.join(projectRoot, 'node_modules', url.substr(1)),
52+
}),
4953
postcssUrl([
5054
{
5155
// Only convert root relative URLs, which CSS-Loader won't process into require().
@@ -83,7 +87,7 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
8387
'postcss-url': 'postcssUrl',
8488
'postcss-custom-properties': 'customProperties'
8589
},
86-
variables: { minimizeCss, baseHref, deployUrl }
90+
variables: { minimizeCss, baseHref, deployUrl, projectRoot }
8791
};
8892

8993
// determine hashing format

tests/e2e/tests/build/styles/inline-urls.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ng } from '../../../utils/process';
1+
import { ng, silentNpm } from '../../../utils/process';
22
import {
33
expectFileToMatch,
44
expectFileToExist,
@@ -7,6 +7,7 @@ import {
77
} from '../../../utils/fs';
88
import { copyProjectAsset } from '../../../utils/assets';
99
import { expectToFail } from '../../../utils/utils';
10+
import { updateJsonFile } from '../../../utils/project';
1011

1112
const imgSvg = `
1213
<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg">
@@ -16,8 +17,11 @@ const imgSvg = `
1617

1718
export default function () {
1819
return Promise.resolve()
20+
.then(() => silentNpm('install', '[email protected]'))
1921
.then(() => writeMultipleFiles({
20-
'src/styles.css': `
22+
'src/styles.scss': `
23+
$fa-font-path: "~font-awesome/font";
24+
@import "~font-awesome/scss/font-awesome";
2125
h1 { background: url('./assets/large.png'); }
2226
h2 { background: url('./assets/small.svg'); }
2327
p { background: url('./assets/small-id.svg#testID'); }
@@ -30,7 +34,16 @@ export default function () {
3034
'src/assets/small-id.svg': imgSvg
3135
}))
3236
.then(() => copyProjectAsset('images/spectrum.png', './assets/large.png'))
37+
.then(() => updateJsonFile('.angular-cli.json', configJson => {
38+
const app = configJson['apps'][0];
39+
app['styles'] = ['styles.scss'];
40+
}))
3341
.then(() => ng('build', '--extract-css', '--aot'))
42+
.then(({ stdout }) => {
43+
if (stdout.match(/postcss-url: \.+: Can't read file '\.+', ignoring/)) {
44+
throw new Error('Expected no postcss-url file read warnings.');
45+
}
46+
})
3447
// Check paths are correctly generated.
3548
.then(() => expectFileToMatch('dist/styles.bundle.css',
3649
/url\([\'"]?large\.[0-9a-f]{20}\.png[\'"]?\)/))

0 commit comments

Comments
 (0)