@@ -31,22 +31,21 @@ const resource = {
3131 static : `${ paths . src . static } /**/*`
3232 } ,
3333 vendor : {
34- js : [ 'lodash' , 'dateformat' , 'react' , 'react-dom' , 'react-redux' , 'redux' , 'react-router' , 'react-router-redux' , 'react-tap-event-plugin' , ' material-ui']
34+ js : [ 'lodash' , 'dateformat' , 'react' , 'react-dom' , 'react-redux' , 'redux' , 'react-router' , '@ material-ui/core ' ]
3535 }
3636}
3737
3838import gulp from 'gulp'
3939import gulpLoaderPlugins from 'gulp-load-plugins'
4040import del from 'del'
41- import path from 'path'
4241import webpack from 'webpack'
4342import webpackStream from 'webpack-stream'
4443import runSequence from 'run-sequence'
4544import browserSyncTool from 'browser-sync'
4645import RevAll from 'gulp-rev-all'
4746
4847const $ = gulpLoaderPlugins ( )
49- const browserSync = browserSyncTool . create ( )
48+ const browserSync = browserSyncTool . create ( )
5049
5150let production = false
5251
@@ -55,7 +54,7 @@ gulp.task('default', ['build', 'server'])
5554
5655//## build for developer
5756gulp . task ( 'build' , ( callback ) =>
58- runSequence ( 'clean' , [ 'build:pug' , 'build:sass' , 'build:webpack ' , 'build:static ' ] , callback )
57+ runSequence ( 'clean' , [ 'build:pug' , 'build:sass' , 'build:static ' , 'build:webpack ' ] , callback )
5958)
6059
6160//## build production
@@ -78,28 +77,30 @@ gulp.task('revision', (callback) =>
7877
7978// compile Webpack [ ES201x(Babel) / Vue -> SPA(main.js) ]
8079gulp . task ( 'build:webpack' , ( ) => {
81- process . env . NODE_ENV = ( production == true ) ? 'production' : 'development'
82- let plugins = [
83- new webpack . optimize . CommonsChunkPlugin ( { name : "vendor" , filename : "vendor.bundle.js" } ) ,
84- new webpack . DefinePlugin ( { 'process.env.NODE_ENV' : JSON . stringify ( process . env . NODE_ENV ) } )
80+ process . env . NODE_ENV = production ? 'production' : 'development'
81+ const plugins = [
82+ new webpack . ProvidePlugin ( { jQuery : "jquery" , $ : "jquery" } ) ,
83+ new webpack . IgnorePlugin ( / ^ \. \/ l o c a l e $ / , / m o m e n t $ / ) ,
84+ new webpack . DefinePlugin ( { 'process.env.NODE_ENV' : JSON . stringify ( process . env . NODE_ENV ) } ) ,
8585 ]
86- if ( production ) {
87- plugins . push ( new webpack . optimize . UglifyJsPlugin ( { compress : { warnings : false } } ) )
88- plugins . push ( new webpack . optimize . ModuleConcatenationPlugin ( ) )
89- }
9086 return gulp . src ( resource . src . webpack . babel )
9187 . pipe ( $ . plumber ( ) )
9288 . pipe ( webpackStream ( {
93- devtool : '#source-map' ,
89+ mode : process . env . NODE_ENV ,
90+ devtool : production ? false : '#source-map' ,
9491 entry : {
95- app : `${ paths . src . js } /main.js` ,
92+ main : `${ paths . src . js } /main.js` ,
9693 vendor : resource . vendor . js
9794 } ,
98- output : { filename : 'bundle.js' } ,
95+ output : { filename : '[name].bundle.js' } ,
96+ optimization : {
97+ splitChunks : { name : 'vendor' , chunks : 'initial' } ,
98+ noEmitOnErrors : true ,
99+ } ,
99100 watch : ! production ,
100101 module : {
101102 rules : [
102- { test : / \. ( j s | j s x ) $ / , loader : 'babel-loader' , exclude : / n o d e _ m o d u l e s / }
103+ { test : / \. ( j s | j s x ) $ / , use : 'babel-loader' , exclude : / n o d e _ m o d u l e s / } ,
103104 ]
104105 } ,
105106 resolve : {
@@ -120,8 +121,6 @@ gulp.task('build:pug', () => {
120121 return gulp . src ( resource . src . pug )
121122 . pipe ( $ . plumber ( ) )
122123 . pipe ( $ . pug ( ) )
123- . pipe ( $ . htmlhint ( ) )
124- . pipe ( $ . htmlhint . reporter ( ) )
125124 . pipe ( gulp . dest ( paths . dist . root ) )
126125 . pipe ( browserSync . stream ( ) )
127126} )
@@ -130,9 +129,8 @@ gulp.task('build:pug', () => {
130129gulp . task ( 'build:sass' , ( ) => {
131130 return gulp . src ( resource . src . sass )
132131 . pipe ( $ . plumber ( ) )
133- . pipe ( $ . sass ( ) )
134132 . pipe ( $ . concat ( 'style.css' ) )
135- . pipe ( $ . pleeease ( ) )
133+ . pipe ( $ . sass ( { outputStyle : 'compressed' } ) )
136134 . pipe ( gulp . dest ( paths . dist . css ) )
137135 . pipe ( browserSync . stream ( ) )
138136} )
0 commit comments