@@ -18,50 +18,41 @@ var plugins = [
1818 // 该配置假定你引入的 vendor 存在于 node_modules 目录中
1919 return module . context && module . context . indexOf ( 'node_modules' ) !== - 1 ;
2020 }
21+ } ) ,
22+ new webpack . DefinePlugin ( {
23+ // 定义全局变量
24+ 'process.env' :{
25+ 'NODE_ENV' : JSON . stringify ( nodeEnv )
26+ }
2127 } )
2228]
23- var app = [
24- 'babel-polyfill' ,
25- './src/index'
26- ]
29+ var app = [ './index' ]
2730if ( isPro ) {
2831 plugins . push (
2932 new webpack . optimize . UglifyJsPlugin ( {
30- compress : {
31- warnings : false ,
32- drop_console : false
33- }
34- } ) ,
35- new webpack . DefinePlugin ( {
36- // 定义全局变量
37- 'process.env' :{
38- 'NODE_ENV' : JSON . stringify ( nodeEnv )
39- }
33+ sourceMap : true ,
34+ comments : false
4035 } )
4136 )
4237} else {
43- app . push ( 'webpack -hot-middleware/ client?path= http://localhost:3011/__webpack_hmr&reload=true&noInfo=false&quiet=false ')
38+ app . unshift ( 'react -hot-loader/patch' , 'webpack-dev-server/ client?http://localhost:3011' , 'webpack/hot/only-dev-server ')
4439 plugins . push (
45- new webpack . DefinePlugin ( {
46- // 定义全局变量
47- 'process.env' :{
48- 'NODE_ENV' : JSON . stringify ( nodeEnv )
49- } ,
50- BASE_URL : JSON . stringify ( 'http://localhost:9009' ) ,
51- } ) ,
52- new webpack . HotModuleReplacementPlugin ( )
40+ new webpack . HotModuleReplacementPlugin ( ) ,
41+ new webpack . NamedModulesPlugin ( ) ,
42+ new webpack . NoEmitOnErrorsPlugin ( )
5343 )
5444}
5545
5646module . exports = {
57- devtool : isPro ? 'source-map' : 'cheap-eval-source-map' ,
47+ context : path . resolve ( __dirname , 'src' ) ,
48+ devtool : isPro ? 'source-map' : 'inline-source-map' ,
5849 entry : {
5950 app : app
6051 } ,
6152 output : {
6253 filename : '[name].js' ,
6354 path : path . join ( __dirname , 'build' ) ,
64- publicPath : isPro ? './build/' : 'http://localhost:3011 /build/' ,
55+ publicPath : isPro ? './build/' : '/build/' ,
6556 chunkFilename : '[name].js'
6657 } ,
6758 // BASE_URL是全局的api接口访问地址
@@ -77,21 +68,31 @@ module.exports = {
7768
7869 module : {
7970 rules : [ {
80- test : / \. ( j s | j s x ) $ / ,
81- use : [ 'babel-loader' ] ,
82- exclude : / n o d e _ m o d u l e s / ,
83- include : path . join ( __dirname , 'src' )
71+ test : / \. j s $ / ,
72+ exclude : / ( n o d e _ m o d u l e s | b o w e r _ c o m p o n e n t s ) / ,
73+ use : {
74+ loader : 'babel-loader?cacheDirectory=true'
75+ }
8476 } , {
8577 test : / \. ( l e s s | c s s ) $ / ,
8678 use : ExtractTextPlugin . extract ( {
8779 use : [ "css-loader" , "less-loader" , "postcss-loader" ]
8880 } )
8981 } , {
90- test : / \. ( p n g | j p g | g i f | m d ) $ / ,
91- use : [ 'file-loader?limit=10000&name=[md5:hash:base64:10].[ext]' ]
92- } , {
93- test : / \. s v g ( \? v = \d + \. \d + \. \d + ) ? $ / ,
94- use : [ 'url-loader?limit=10000&mimetype=image/svg+xml' ]
95- } ] ,
96- }
82+ test : / \. ( p n g | j p g | g i f | s v g | e o t | t t f | w o f f | w o f f 2 ) $ / ,
83+ use : [ 'url-loader?limit=10000&name=files/[md5:hash:base64:10].[ext]' ]
84+ } ]
85+ } ,
86+ devServer : {
87+ hot : true ,
88+ compress : true ,
89+ port : 3011 ,
90+ historyApiFallback : true ,
91+ contentBase : path . resolve ( __dirname ) ,
92+ publicPath : '/build/' ,
93+ stats : {
94+ modules : false ,
95+ chunks : false
96+ } ,
97+ } ,
9798} ;
0 commit comments