Skip to content

Commit 4eb405b

Browse files
clydinMRHarrison
authored andcommitted
fix(webpack): correctly load component stylesheets (angular#3511)
1 parent 5a05431 commit 4eb405b

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

packages/angular-cli/models/webpack-build-utils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export function makeCssLoaders(stylePaths: string[] = []) {
6767
{ test: /\.styl$/, loaders: ['stylus-loader'] }
6868
];
6969

70-
const commonLoaders = ['css-loader', 'postcss-loader'];
70+
const commonLoaders = ['postcss-loader'];
7171

7272
// load component css as raw strings
7373
let cssLoaders: any = baseRules.map(({test, loaders}) => ({
@@ -78,7 +78,7 @@ export function makeCssLoaders(stylePaths: string[] = []) {
7878
// load global css as css files
7979
cssLoaders.push(...baseRules.map(({test, loaders}) => ({
8080
include: stylePaths, test, loaders: ExtractTextPlugin.extract({
81-
loader: [...commonLoaders, ...loaders],
81+
loader: ['css-loader', ...commonLoaders, ...loaders],
8282
fallbackLoader: 'style-loader'
8383
})
8484
})));
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import {
2+
writeMultipleFiles,
3+
deleteFile,
4+
expectFileToMatch,
5+
replaceInFile
6+
} from '../../../utils/fs';
7+
import { ng } from '../../../utils/process';
8+
import { stripIndents } from 'common-tags';
9+
import { updateJsonFile } from '../../../utils/project';
10+
import { expectToFail } from '../../../utils/utils';
11+
12+
export default function () {
13+
return writeMultipleFiles({
14+
'src/styles.scss': stripIndents`
15+
@import './imported-styles.scss';
16+
body { background-color: blue; }
17+
`,
18+
'src/imported-styles.scss': stripIndents`
19+
p { background-color: red; }
20+
`,
21+
'src/app/app.component.scss': stripIndents`
22+
.outer {
23+
.inner {
24+
background: #fff;
25+
}
26+
}
27+
`})
28+
.then(() => deleteFile('src/app/app.component.css'))
29+
.then(() => updateJsonFile('angular-cli.json', configJson => {
30+
const app = configJson['apps'][0];
31+
app['styles'] = ['styles.scss'];
32+
}))
33+
.then(() => replaceInFile('src/app/app.component.ts',
34+
'./app.component.css', './app.component.scss'))
35+
.then(() => ng('build'))
36+
.then(() => expectToFail(() => expectFileToMatch('dist/styles.bundle.css', /exports/)))
37+
.then(() => expectToFail(() => expectFileToMatch('dist/main.bundle.js',
38+
/".*module\.exports.*\.outer.*background:/)));
39+
}

0 commit comments

Comments
 (0)