-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@angular/cli): allow component css imports (#4667)
Fix #4285
- Loading branch information
1 parent
61fc099
commit e55cb82
Showing
8 changed files
with
84 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { | ||
writeMultipleFiles, | ||
deleteFile, | ||
expectFileToMatch, | ||
replaceInFile | ||
} from '../../../utils/fs'; | ||
import { expectToFail } from '../../../utils/utils'; | ||
import { ng } from '../../../utils/process'; | ||
import { stripIndents } from 'common-tags'; | ||
import { updateJsonFile } from '../../../utils/project'; | ||
|
||
export default function () { | ||
const extensions = ['css', 'scss', 'less', 'styl']; | ||
let promise = Promise.resolve(); | ||
|
||
extensions.forEach(ext => { | ||
promise = promise.then(() => { | ||
return writeMultipleFiles({ | ||
[`src/styles.${ext}`]: stripIndents` | ||
@import './imported-styles.${ext}'; | ||
body { background-color: #00f; } | ||
`, | ||
[`src/imported-styles.${ext}`]: stripIndents` | ||
p { background-color: #f00; } | ||
`, | ||
[`src/app/app.component.${ext}`]: stripIndents` | ||
@import './imported-component-styles.${ext}'; | ||
.outer { | ||
.inner { | ||
background: #fff; | ||
} | ||
} | ||
`, | ||
[`src/app/imported-component-styles.${ext}`]: stripIndents` | ||
h1 { background: #000; } | ||
`}) | ||
// change files to use preprocessor | ||
.then(() => updateJsonFile('angular-cli.json', configJson => { | ||
const app = configJson['apps'][0]; | ||
app['styles'] = [`styles.${ext}`]; | ||
})) | ||
.then(() => replaceInFile('src/app/app.component.ts', | ||
'./app.component.css', `./app.component.${ext}`)) | ||
// run build app | ||
.then(() => ng('build', '--extract-css', '--sourcemap')) | ||
// verify global styles | ||
.then(() => expectFileToMatch('dist/styles.bundle.css', | ||
/body\s*{\s*background-color: #00f;\s*}/)) | ||
.then(() => expectFileToMatch('dist/styles.bundle.css', | ||
/p\s*{\s*background-color: #f00;\s*}/)) | ||
// verify global styles sourcemap | ||
.then(() => expectToFail(() => | ||
expectFileToMatch('dist/styles.bundle.css', '"mappings":""'))) | ||
// verify component styles | ||
.then(() => expectFileToMatch('dist/main.bundle.js', | ||
/.outer.*.inner.*background:\s*#[fF]+/)) | ||
.then(() => expectFileToMatch('dist/main.bundle.js', | ||
/h1.*background:\s*#000+/)) | ||
// change files back | ||
.then(() => updateJsonFile('angular-cli.json', configJson => { | ||
const app = configJson['apps'][0]; | ||
app['styles'] = ['styles.css']; | ||
})) | ||
.then(() => replaceInFile('src/app/app.component.ts', | ||
`./app.component.${ext}`, './app.component.css')); | ||
}); | ||
}); | ||
|
||
return promise; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.