-
Notifications
You must be signed in to change notification settings - Fork 12k
fix(build): Use static files for styles #2646
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
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
099d21b
Add extract-text-webpack-plugin dependency
jimitndiaye ca966bf
Use extract-text-plugin to extract css bundle for production builds.
jimitndiaye ec26e19
Added e2e tests for prod build covering style bundling for css, less …
jimitndiaye 78f8610
Update production build e2e test to expect 32 character content hash …
jimitndiaye 9bec7c9
fix paths for styles.less and styles.scss in css e2e test
jimitndiaye b418afd
use glob to find path to hashed styles bundle for prod build
jimitndiaye 0a6b40d
chore(style): remove unused fs import
jimitndiaye File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,13 +1,40 @@ | ||
const path = require('path'); | ||
|
||
export const getWebpackDevConfigPartial = function(projectRoot: string, appConfig: any) { | ||
const appRoot = path.resolve(projectRoot, appConfig.root); | ||
const styles = appConfig.styles | ||
? appConfig.styles.map((style: string) => path.resolve(appRoot, style)) | ||
: []; | ||
const cssLoaders = ['style-loader', 'css-loader?sourcemap', 'postcss-loader']; | ||
return { | ||
devtool: 'cheap-module-source-map', | ||
output: { | ||
path: path.resolve(projectRoot, appConfig.outDir), | ||
filename: '[name].bundle.js', | ||
sourceMapFilename: '[name].map', | ||
chunkFilename: '[id].chunk.js' | ||
}, | ||
module: { | ||
rules: [ | ||
// outside of main, load it via style-loader for development builds | ||
{ | ||
include: styles, | ||
test: /\.css$/, | ||
loaders: cssLoaders | ||
}, { | ||
include: styles, | ||
test: /\.styl$/, | ||
loaders: [...cssLoaders, 'stylus-loader?sourcemap'] | ||
}, { | ||
include: styles, | ||
test: /\.less$/, | ||
loaders: [...cssLoaders, 'less-loader?sourcemap'] | ||
}, { | ||
include: styles, | ||
test: /\.scss$|\.sass$/, | ||
loaders: [...cssLoaders, 'sass-loader?sourcemap'] | ||
}, | ||
] | ||
} | ||
}; | ||
}; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,19 +1,53 @@ | ||
import * as glob from 'glob'; | ||
|
||
import {writeMultipleFiles, expectFileToMatch} from '../../../utils/fs'; | ||
import {ng} from '../../../utils/process'; | ||
import {updateJsonFile} from '../../../utils/project'; | ||
|
||
|
||
export default function() { | ||
return writeMultipleFiles({ | ||
'src/styles.css': ` | ||
@import './imported-styles.css'; | ||
|
||
body { background-color: blue; } | ||
`, | ||
'src/imported-styles.css': ` | ||
p { background-color: red; } | ||
`, | ||
'src/styles.less': ` | ||
.outer { | ||
.inner { | ||
background: #fff; | ||
} | ||
} | ||
`, | ||
'src/styles.scss': ` | ||
.upper { | ||
.lower { | ||
background: #def; | ||
} | ||
} | ||
` | ||
}) | ||
.then(() => updateJsonFile('angular-cli.json', configJson => { | ||
const app = configJson['apps'][0]; | ||
app['styles'].push('styles.less'); | ||
app['styles'].push('styles.scss'); | ||
})) | ||
.then(() => ng('build')) | ||
.then(() => expectFileToMatch('dist/styles.bundle.js', 'body { background-color: blue; }')) | ||
.then(() => expectFileToMatch('dist/styles.bundle.js', 'p { background-color: red; }')); | ||
.then(() => expectFileToMatch('dist/styles.bundle.js', 'p { background-color: red; }')) | ||
.then(() => expectFileToMatch('dist/styles.bundle.js', /.outer.*.inner.*background:\s*#[fF]+/)) | ||
.then(() => expectFileToMatch('dist/styles.bundle.js', /.upper.*.lower.*background.*#def/)) | ||
|
||
.then(() => ng('build', '--prod')) | ||
.then(() => new Promise<string>(() => | ||
glob.sync('dist/styles.*.bundle.css').find(file => !!file))) | ||
.then((styles) => | ||
expectFileToMatch(styles, 'body { background-color: blue; }') | ||
.then(() => expectFileToMatch(styles, 'p { background-color: red; }') | ||
.then(() => expectFileToMatch(styles, /.outer.*.inner.*background:\s*#[fF]+/)) | ||
.then(() => expectFileToMatch(styles, /.upper.*.lower.*background.*#def/))) | ||
); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You never resolve this promise, causing tests to stop early. This test is causing our e2e to not continue.
Also, no need to return a promise, just return the
glob.sync
.