Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(webpack): correctly load component stylesheets #3511

Merged
merged 1 commit into from Dec 16, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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:/)));
}