Skip to content

Commit

Permalink
fix(webpack): correctly load component stylesheets (#3511)
Browse files Browse the repository at this point in the history
  • Loading branch information
clydin authored and hansl committed Dec 16, 2016
1 parent 71047fc commit d4da7bd
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/angular-cli/models/webpack-build-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function makeCssLoaders(stylePaths: string[] = []) {
{ test: /\.styl$/, loaders: ['stylus-loader'] }
];

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

// load component css as raw strings
let cssLoaders: any = baseRules.map(({test, loaders}) => ({
Expand All @@ -78,7 +78,7 @@ export function makeCssLoaders(stylePaths: string[] = []) {
// load global css as css files
cssLoaders.push(...baseRules.map(({test, loaders}) => ({
include: stylePaths, test, loaders: ExtractTextPlugin.extract({
loader: [...commonLoaders, ...loaders],
loader: ['css-loader', ...commonLoaders, ...loaders],
fallbackLoader: 'style-loader'
})
})));
Expand Down
39 changes: 39 additions & 0 deletions tests/e2e/tests/build/styles/loaders.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {
writeMultipleFiles,
deleteFile,
expectFileToMatch,
replaceInFile
} from '../../../utils/fs';
import { ng } from '../../../utils/process';
import { stripIndents } from 'common-tags';
import { updateJsonFile } from '../../../utils/project';
import { expectToFail } from '../../../utils/utils';

export default function () {
return writeMultipleFiles({
'src/styles.scss': stripIndents`
@import './imported-styles.scss';
body { background-color: blue; }
`,
'src/imported-styles.scss': stripIndents`
p { background-color: red; }
`,
'src/app/app.component.scss': stripIndents`
.outer {
.inner {
background: #fff;
}
}
`})
.then(() => deleteFile('src/app/app.component.css'))
.then(() => updateJsonFile('angular-cli.json', configJson => {
const app = configJson['apps'][0];
app['styles'] = ['styles.scss'];
}))
.then(() => replaceInFile('src/app/app.component.ts',
'./app.component.css', './app.component.scss'))
.then(() => ng('build'))
.then(() => expectToFail(() => expectFileToMatch('dist/styles.bundle.css', /exports/)))
.then(() => expectToFail(() => expectFileToMatch('dist/main.bundle.js',
/".*module\.exports.*\.outer.*background:/)));
}

0 comments on commit d4da7bd

Please sign in to comment.