1
-
2
-
3
1
var pkg = require ( './package.json' ) ;
4
2
// https://github.com/gulpjs/gulp/blob/master/docs/README.md
5
3
var gulp = require ( 'gulp' ) ;
6
4
// http://webpack.github.io/docs/
7
5
var webpack = require ( 'webpack' ) ;
8
6
// https://github.com/shama/webpack-stream
9
7
var 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' ) ;
11
12
12
13
gulp . task (
13
14
pkg . name + '/build' ,
14
15
function ( ) {
15
- return gulp
16
- . src ( './src/index.js' )
17
- . pipe ( webpackStream ( {
16
+ var normalWebpackStream = {
18
17
module : {
19
18
loaders : [
20
19
// https://github.com/babel/babel-loader
@@ -26,12 +25,7 @@ gulp.task(
26
25
]
27
26
} ,
28
27
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
+
35
29
// http://webpack.github.io/docs/list-of-plugins.html#bannerplugin
36
30
new webpack . BannerPlugin (
37
31
'/*\n' +
@@ -48,10 +42,37 @@ gulp.task(
48
42
output : {
49
43
library : pkg . name ,
50
44
libraryTarget : 'umd' ,
51
- filename : pkg . name + '.min. js'
45
+ filename : pkg . name + '.js'
52
46
}
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 ) ;
55
76
}
56
77
) ;
57
78
0 commit comments