Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/@angular/cli/models/webpack-configs/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
};

return [
postcssUrl({
filter: ({ url }: { url: string }) => url.startsWith('~'),
url: ({ url }: { url: string }) => path.join(projectRoot, 'node_modules', url.substr(1)),
}),
postcssUrl([
{
// Only convert root relative URLs, which CSS-Loader won't process into require().
Expand Down Expand Up @@ -98,7 +102,7 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
'cssnano': 'cssnano',
'postcss-custom-properties': 'customProperties'
},
variables: { minimizeCss, baseHref, deployUrl }
variables: { minimizeCss, baseHref, deployUrl, projectRoot }
};

// determine hashing format
Expand Down
17 changes: 15 additions & 2 deletions tests/e2e/tests/build/styles/inline-urls.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ng } from '../../../utils/process';
import { ng, silentNpm } from '../../../utils/process';
import {
expectFileToMatch,
expectFileToExist,
Expand All @@ -7,6 +7,7 @@ import {
} from '../../../utils/fs';
import { copyProjectAsset } from '../../../utils/assets';
import { expectToFail } from '../../../utils/utils';
import { updateJsonFile } from '../../../utils/project';

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

export default function () {
return Promise.resolve()
.then(() => silentNpm('install', 'font-awesome@4.7.0'))
.then(() => writeMultipleFiles({
'src/styles.css': `
'src/styles.scss': `
$fa-font-path: "~font-awesome/font";
@import "~font-awesome/scss/font-awesome";
h1 { background: url('./assets/large.png'); }
h2 { background: url('./assets/small.svg'); }
p { background: url('./assets/small-id.svg#testID'); }
Expand All @@ -30,7 +34,16 @@ export default function () {
'src/assets/small-id.svg': imgSvg
}))
.then(() => copyProjectAsset('images/spectrum.png', './assets/large.png'))
.then(() => updateJsonFile('.angular-cli.json', configJson => {
const app = configJson['apps'][0];
app['styles'] = ['styles.scss'];
}))
.then(() => ng('build', '--extract-css', '--aot'))
.then(({ stdout }) => {
if (stdout.match(/postcss-url: \.+: Can't read file '\.+', ignoring/)) {
throw new Error('Expected no postcss-url file read warnings.');
}
})
// Check paths are correctly generated.
.then(() => expectFileToMatch('dist/styles.bundle.css',
/url\([\'"]?large\.[0-9a-f]{20}\.png[\'"]?\)/))
Expand Down