1
1
import * as webpack from 'webpack' ;
2
2
import * as path from 'path' ;
3
3
import {
4
- SuppressExtractedTextChunksWebpackPlugin
5
- } from '../../plugins/suppress-entry-chunks-webpack-plugin' ;
4
+ CleanCssWebpackPlugin ,
5
+ SuppressExtractedTextChunksWebpackPlugin ,
6
+ } from '../../plugins/webpack' ;
6
7
import { extraEntryParser , getOutputHashFormat } from './utils' ;
7
8
import { WebpackConfigOptions } from '../webpack-config' ;
8
9
import { pluginArgs , postcssArgs } from '../../tasks/eject' ;
9
- import { CleanCssWebpackPlugin } from '../../plugins/cleancss-webpack-plugin' ;
10
10
11
11
const postcssUrl = require ( 'postcss-url' ) ;
12
12
const autoprefixer = require ( 'autoprefixer' ) ;
13
13
const ExtractTextPlugin = require ( 'extract-text-webpack-plugin' ) ;
14
14
const postcssImports = require ( 'postcss-import' ) ;
15
+ const PostcssCliResources = require ( '../../plugins/webpack' ) . PostcssCliResources ;
15
16
16
17
/**
17
18
* Enumerate loaders and their dependencies from this file to let the dependency validator
18
19
* know they are used.
19
20
*
20
- * require('exports-loader')
21
21
* require('style-loader')
22
22
* require('postcss-loader')
23
- * require('css-loader')
24
23
* require('stylus')
25
24
* require('stylus-loader')
26
25
* require('less')
@@ -48,6 +47,8 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
48
47
const maximumInlineSize = 10 ;
49
48
// Minify/optimize css in production.
50
49
const minimizeCss = buildOptions . target === 'production' ;
50
+ // determine hashing format
51
+ const hashFormat = getOutputHashFormat ( buildOptions . outputHashing ) ;
51
52
// Convert absolute resource URLs to account for base-href and deploy-url.
52
53
const baseHref = wco . buildOptions . baseHref || '' ;
53
54
const deployUrl = wco . buildOptions . deployUrl || '' ;
@@ -122,21 +123,26 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
122
123
} ,
123
124
{ url : 'rebase' } ,
124
125
] ) ,
126
+ PostcssCliResources ( {
127
+ deployUrl : loader . loaders [ loader . loaderIndex ] . options . ident == 'extracted' ? '' : deployUrl ,
128
+ loader,
129
+ filename : `[name]${ hashFormat . file } .[ext]` ,
130
+ } ) ,
125
131
autoprefixer ( { grid : true } ) ,
126
132
] ;
127
133
} ;
128
134
( postcssPluginCreator as any ) [ postcssArgs ] = {
135
+ imports : {
136
+ '@angular/cli/plugins/webpack' : 'PostcssCliResources' ,
137
+ } ,
129
138
variableImports : {
130
139
'autoprefixer' : 'autoprefixer' ,
131
140
'postcss-url' : 'postcssUrl' ,
132
141
'postcss-import' : 'postcssImports' ,
133
142
} ,
134
- variables : { minimizeCss , baseHref, deployUrl, projectRoot, maximumInlineSize }
143
+ variables : { hashFormat , baseHref, deployUrl, projectRoot, maximumInlineSize }
135
144
} ;
136
145
137
- // determine hashing format
138
- const hashFormat = getOutputHashFormat ( buildOptions . outputHashing ) ;
139
-
140
146
// use includePaths from appConfig
141
147
const includePaths : string [ ] = [ ] ;
142
148
let lessPathOptions : { paths : string [ ] } ;
@@ -198,29 +204,21 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
198
204
] ;
199
205
200
206
const commonLoaders : webpack . Loader [ ] = [
201
- {
202
- loader : 'css-loader' ,
203
- options : {
204
- sourceMap : cssSourceMap ,
205
- import : false ,
206
- }
207
- } ,
208
- {
209
- loader : 'postcss-loader' ,
210
- options : {
211
- // A non-function property is required to workaround a webpack option handling bug
212
- ident : 'postcss' ,
213
- plugins : postcssPluginCreator ,
214
- sourceMap : cssSourceMap
215
- }
216
- }
207
+ { loader : 'raw-loader' } ,
217
208
] ;
218
209
219
210
// load component css as raw strings
220
211
const rules : webpack . Rule [ ] = baseRules . map ( ( { test, use} ) => ( {
221
212
exclude : globalStylePaths , test, use : [
222
- 'exports-loader?module.exports.toString()' ,
223
213
...commonLoaders ,
214
+ {
215
+ loader : 'postcss-loader' ,
216
+ options : {
217
+ ident : 'embedded' ,
218
+ plugins : postcssPluginCreator ,
219
+ sourceMap : cssSourceMap
220
+ }
221
+ } ,
224
222
...( use as webpack . Loader [ ] )
225
223
]
226
224
} ) ) ;
@@ -231,6 +229,14 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
231
229
const extractTextPlugin = {
232
230
use : [
233
231
...commonLoaders ,
232
+ {
233
+ loader : 'postcss-loader' ,
234
+ options : {
235
+ ident : buildOptions . extractCss ? 'extracted' : 'embedded' ,
236
+ plugins : postcssPluginCreator ,
237
+ sourceMap : cssSourceMap
238
+ }
239
+ } ,
234
240
...( use as webpack . Loader [ ] )
235
241
] ,
236
242
// publicPath needed as a workaround https://github.com/angular/angular-cli/issues/4035
0 commit comments