1-
2-
31var pkg = require ( './package.json' ) ;
42// https://github.com/gulpjs/gulp/blob/master/docs/README.md
53var gulp = require ( 'gulp' ) ;
64// http://webpack.github.io/docs/
75var webpack = require ( 'webpack' ) ;
86// https://github.com/shama/webpack-stream
97var webpackStream = require ( 'webpack-stream' ) ;
10-
8+ // https://github.com/dominictarr/event-stream
9+ var es = require ( 'event-stream' ) ;
10+ // https://github.com/justmoon/node-extend
11+ var extend = require ( 'extend' ) ;
1112
1213gulp . task (
1314 pkg . name + '/build' ,
1415 function ( ) {
15- return gulp
16- . src ( './src/index.js' )
17- . pipe ( webpackStream ( {
16+ var normalWebpackStream = {
1817 module : {
1918 loaders : [
2019 // https://github.com/babel/babel-loader
@@ -26,12 +25,7 @@ gulp.task(
2625 ]
2726 } ,
2827 plugins : [
29- // http://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin
30- new webpack . optimize . UglifyJsPlugin ( {
31- compress : {
32- warnings : false
33- }
34- } ) ,
28+
3529 // http://webpack.github.io/docs/list-of-plugins.html#bannerplugin
3630 new webpack . BannerPlugin (
3731 '/*\n' +
@@ -48,10 +42,37 @@ gulp.task(
4842 output : {
4943 library : pkg . name ,
5044 libraryTarget : 'umd' ,
51- filename : pkg . name + '.min. js'
45+ filename : pkg . name + '.js'
5246 }
53- } ) )
54- . pipe ( gulp . dest ( './dist' ) ) ;
47+ } ,
48+ normalStream =
49+ gulp
50+ . src ( './src/index.js' )
51+ . pipe ( webpackStream ( normalWebpackStream ) )
52+ . pipe ( gulp . dest ( './dist' ) ) ;
53+
54+ /**
55+ * Deep copy the normalWebpackStream to customize it for the uglify stream
56+ */
57+ var ulgifyWebpackStream = extend ( true , { } , normalWebpackStream ) ;
58+
59+ ulgifyWebpackStream . plugins . unshift (
60+ // http://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin
61+ new webpack . optimize . UglifyJsPlugin ( {
62+ compress : {
63+ warnings : false
64+ }
65+ } ) ) ;
66+
67+ ulgifyWebpackStream . output . filename = pkg . name + '.min.js' ;
68+
69+ var uglifyStream =
70+ gulp
71+ . src ( './src/index.js' )
72+ . pipe ( webpackStream ( ulgifyWebpackStream ) )
73+ . pipe ( gulp . dest ( './dist' ) ) ;
74+
75+ return es . concat ( normalStream , uglifyStream ) ;
5576 }
5677) ;
5778
0 commit comments