Skip to content

Commit e995e8b

Browse files
committed
feat: add css-with-mapping-loader to enable source mapping for component style
feat: add html-loader feat: inline small SVG files referenced by HTML/CSS as dataURLs
1 parent cbab6f8 commit e995e8b

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

packages/@angular/cli/models/webpack-configs/common.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
124124
rules: [
125125
{ enforce: 'pre', test: /\.js$/, loader: 'source-map-loader', exclude: [nodeModules] },
126126
{ test: /\.json$/, loader: 'json-loader' },
127-
{ test: /\.html$/, loader: 'raw-loader' },
128-
{ test: /\.(eot|svg)$/, loader: `file-loader?name=[name]${hashFormat.file}.[ext]` },
127+
{ test: /\.html$/, loaders: ['html-loader'] },
128+
{ test: /\.(eot|svg)$/, loader: `url-loader?name=images/[name]${hashFormat.file}.[ext]&limit=256` },
129129
{
130130
test: /\.(jpg|png|gif|otf|ttf|woff|woff2)$/,
131-
loader: `url-loader?name=[name]${hashFormat.file}.[ext]&limit=10000`
131+
loader: `url-loader?name=images/[name]${hashFormat.file}.[ext]&limit=10000`
132132
}
133133
].concat(extraRules)
134134
},

packages/@angular/cli/models/webpack-configs/styles.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
3636
// style-loader does not support sourcemaps without absolute publicPath, so it's
3737
// better to disable them when not extracting css
3838
// https://github.com/webpack-contrib/style-loader#recommended-configuration
39-
const cssSourceMap = buildOptions.extractCss && buildOptions.sourcemap;
39+
const cssSourceMap = buildOptions.sourcemap;
4040

4141
// minify/optimize css in production
4242
// autoprefixer is always run separately so disable here
@@ -90,7 +90,12 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
9090

9191
// load component css as raw strings
9292
let rules: any = baseRules.map(({test, loaders}) => ({
93-
exclude: globalStylePaths, test, loaders: ['raw-loader', ...commonLoaders, ...loaders]
93+
exclude: globalStylePaths, test, loaders: [
94+
'css-with-mapping-loader',
95+
`css-loader?${JSON.stringify({ sourceMap: cssSourceMap })}`,
96+
...commonLoaders,
97+
...loaders
98+
]
9499
}));
95100

96101
// load global css as css files

packages/@angular/cli/models/webpack-configs/utils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ export interface HashFormat {
7878
export function getOutputHashFormat(option: string, length = 20): HashFormat {
7979
/* tslint:disable:max-line-length */
8080
const hashFormats: { [option: string]: HashFormat } = {
81-
none: { chunk: '', extract: '', file: '' },
81+
none: { chunk: '', extract: '', file: `.[hash:${length}]` },
8282
media: { chunk: '', extract: '', file: `.[hash:${length}]` },
83-
bundles: { chunk: `.[chunkhash:${length}]`, extract: `.[contenthash:${length}]`, file: '' },
83+
bundles: { chunk: `.[chunkhash:${length}]`, extract: `.[contenthash:${length}]`, file: `.[hash:${length}]` },
8484
all: { chunk: `.[chunkhash:${length}]`, extract: `.[contenthash:${length}]`, file: `.[hash:${length}]` },
8585
};
8686
/* tslint:enable:max-line-length */

packages/@angular/cli/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"chalk": "^1.1.3",
3838
"common-tags": "^1.3.1",
3939
"css-loader": "^0.26.1",
40+
"css-with-mapping-loader": "0.0.5",
4041
"cssnano": "^3.10.0",
4142
"debug": "^2.1.3",
4243
"denodeify": "^1.2.1",
@@ -50,6 +51,7 @@
5051
"fs-extra": "^0.30.0",
5152
"get-caller-file": "^1.0.0",
5253
"glob": "^7.0.3",
54+
"html-loader": "^0.4.4",
5355
"html-webpack-plugin": "^2.19.0",
5456
"inflection": "^1.7.0",
5557
"inquirer": "^0.12.0",

0 commit comments

Comments
 (0)