@@ -2,6 +2,7 @@ import * as path from 'path';
2
2
const WebpackMd5Hash = require ( 'webpack-md5-hash' ) ;
3
3
const CompressionPlugin = require ( 'compression-webpack-plugin' ) ;
4
4
import * as webpack from 'webpack' ;
5
+ const ExtractTextPlugin = require ( 'extract-text-webpack-plugin' ) ;
5
6
6
7
declare module 'webpack' {
7
8
export interface LoaderOptionsPlugin { }
@@ -14,6 +15,11 @@ declare module 'webpack' {
14
15
}
15
16
16
17
export const getWebpackProdConfigPartial = function ( projectRoot : string , appConfig : any ) {
18
+ const appRoot = path . resolve ( projectRoot , appConfig . root ) ;
19
+ const styles = appConfig . styles
20
+ ? appConfig . styles . map ( ( style : string ) => path . resolve ( appRoot , style ) )
21
+ : [ ] ;
22
+ const cssLoaders = [ 'css-loader?sourcemap&minimize' , 'postcss-loader' ] ;
17
23
return {
18
24
devtool : 'source-map' ,
19
25
output : {
@@ -23,7 +29,30 @@ export const getWebpackProdConfigPartial = function(projectRoot: string, appConf
23
29
sourceMapFilename : '[name].[chunkhash].bundle.map' ,
24
30
chunkFilename : '[id].[chunkhash].chunk.js'
25
31
} ,
32
+ module : {
33
+ rules : [
34
+ // outside of main, load it via extract-text-plugin for production builds
35
+ {
36
+ include : styles ,
37
+ test : / \. c s s $ / ,
38
+ loaders : ExtractTextPlugin . extract ( cssLoaders )
39
+ } , {
40
+ include : styles ,
41
+ test : / \. s t y l $ / ,
42
+ loaders : ExtractTextPlugin . extract ( [ ...cssLoaders , 'stylus-loader?sourcemap' ] )
43
+ } , {
44
+ include : styles ,
45
+ test : / \. l e s s $ / ,
46
+ loaders : ExtractTextPlugin . extract ( [ ...cssLoaders , 'less-loader?sourcemap' ] )
47
+ } , {
48
+ include : styles ,
49
+ test : / \. s c s s $ | \. s a s s $ / ,
50
+ loaders : ExtractTextPlugin . extract ( [ ...cssLoaders , 'sass-loader?sourcemap' ] )
51
+ } ,
52
+ ]
53
+ } ,
26
54
plugins : [
55
+ new ExtractTextPlugin ( '[name].[contenthash].bundle.css' ) ,
27
56
new WebpackMd5Hash ( ) ,
28
57
new webpack . DefinePlugin ( {
29
58
'process.env.NODE_ENV' : JSON . stringify ( 'production' )
0 commit comments