@@ -2,6 +2,7 @@ import * as path from 'path';
22const WebpackMd5Hash = require ( 'webpack-md5-hash' ) ;
33const CompressionPlugin = require ( 'compression-webpack-plugin' ) ;
44import * as webpack from 'webpack' ;
5+ const ExtractTextPlugin = require ( 'extract-text-webpack-plugin' ) ;
56
67declare module 'webpack' {
78 export interface LoaderOptionsPlugin { }
@@ -14,6 +15,11 @@ declare module 'webpack' {
1415}
1516
1617export 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' ] ;
1723 return {
1824 devtool : 'source-map' ,
1925 output : {
@@ -22,7 +28,30 @@ export const getWebpackProdConfigPartial = function(projectRoot: string, appConf
2228 sourceMapFilename : '[name].[chunkhash].bundle.map' ,
2329 chunkFilename : '[id].[chunkhash].chunk.js'
2430 } ,
31+ module : {
32+ rules : [
33+ // outside of main, load it via extract-text-plugin for production builds
34+ {
35+ include : styles ,
36+ test : / \. c s s $ / ,
37+ loaders : ExtractTextPlugin . extract ( cssLoaders )
38+ } , {
39+ include : styles ,
40+ test : / \. s t y l $ / ,
41+ loaders : ExtractTextPlugin . extract ( [ ...cssLoaders , 'stylus-loader?sourcemap' ] )
42+ } , {
43+ include : styles ,
44+ test : / \. l e s s $ / ,
45+ loaders : ExtractTextPlugin . extract ( [ ...cssLoaders , 'less-loader?sourcemap' ] )
46+ } , {
47+ include : styles ,
48+ test : / \. s c s s $ | \. s a s s $ / ,
49+ loaders : ExtractTextPlugin . extract ( [ ...cssLoaders , 'sass-loader?sourcemap' ] )
50+ } ,
51+ ]
52+ } ,
2553 plugins : [
54+ new ExtractTextPlugin ( '[name].[contenthash].bundle.css' ) ,
2655 new WebpackMd5Hash ( ) ,
2756 new webpack . DefinePlugin ( {
2857 'process.env.NODE_ENV' : JSON . stringify ( 'production' )
0 commit comments