11const path = require ( 'path' ) ;
22const webpack = require ( 'webpack' ) ;
3+ const NODE_ENV = process . argv . indexOf ( '-p' ) !== - 1 ? 'production' : 'development' ;
34const ROOT_PATH = path . resolve ( __dirname , './' ) ;
5+ const ExtractTextPlugin = require ( 'extract-text-webpack-plugin' ) ;
6+
7+ const sassImports = [
8+ path . resolve ( __dirname , './src/sass/includes/_includes.scss' ) ,
9+ path . resolve ( __dirname , './src/sass/includes/variables.scss' )
10+ ] ;
11+
12+ const isProduction = ( ) => NODE_ENV === 'production' ;
413
514const isExternal = ( module ) => {
615 let userRequest = module . userRequest ;
@@ -48,6 +57,29 @@ module.exports = {
4857 {
4958 test : / \. ( p n g | j p g | g i f | s v g ) $ / ,
5059 use : [ 'url-loader?limit=8192&name=[path][name].[ext]?[hash]' ]
60+ } ,
61+
62+ {
63+ test : / \. c s s $ / ,
64+ use : ExtractTextPlugin . extract ( {
65+ fallback : 'style-loader' ,
66+ use : [
67+ { loader : 'css-loader' , options : { sourceMap : ! isProduction ( ) } } ,
68+ { loader : 'postcss-loader' , options : { sourceMap : ! isProduction ( ) } }
69+ ]
70+ } )
71+ } ,
72+ {
73+ test : / \. ( s a s s | s c s s ) $ / ,
74+ use : ExtractTextPlugin . extract ( {
75+ fallback : 'style-loader' ,
76+ use : [
77+ { loader : 'css-loader' , options : { sourceMap : ! isProduction ( ) } } ,
78+ { loader : 'postcss-loader' , options : { sourceMap : ! isProduction ( ) } } ,
79+ { loader : 'sass-loader' , options : { sourceMap : ! isProduction ( ) } } ,
80+ { loader : 'sass-resources-loader' , options : { resources : sassImports } }
81+ ]
82+ } )
5183 }
5284 ]
5385 } ,
@@ -56,6 +88,12 @@ module.exports = {
5688 new webpack . optimize . CommonsChunkPlugin ( {
5789 name : 'vendor' ,
5890 minChunks : ( module ) => isExternal ( module )
59- } )
91+ } ) ,
92+
93+ new ExtractTextPlugin ( {
94+ filename : 'styles/[name].[hash].css' ,
95+ allChunks : true ,
96+ disable : ! isProduction ( )
97+ } ) ,
6098 ]
6199} ;
0 commit comments