-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathgulpfile.js
176 lines (149 loc) · 4.31 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
var gulp = require('gulp'),
fs = require("fs"),
rename = require("gulp-rename"),
gulpif = require('gulp-if');
gbrowserify = require('gulp-browserify'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
livereload = require('gulp-livereload');
var browserify = require('browserify');
var watchify = require('watchify');
var source = require('vinyl-source-stream');
// es6 related things
var babel = require('gulp-babel');
var babelify = require("babelify");
// for sass compile and live reload:
var sass = require('gulp-sass'),
autoprefix = require('gulp-autoprefixer'),
minifyCSS = require('gulp-minify-css');
/**
* parse cli options:
* --app=editor or client
* --env=development or production
*/
var argv = require('minimist')(process.argv.slice(2));
var paths = {
scss: 'scss/react-html5-video.scss',
jsDemoMain:"demo/app/app.demo.js",
dest: "./demo/build",
jsLib: "./src/**/*.js",
}
// ---------------------------------------
gulp.task('scss', function() {
// console.log('-----build main.scss');
gulp.src( paths.scss )
.pipe(sass())
.on( "error", handleError)
.pipe(autoprefix('last 2 versions'))
.pipe(minifyCSS())
.pipe(gulp.dest(argv.env === 'production'?"./lib": paths.dest ))
.pipe(
gulpif(argv.env!='production',livereload())
);
});
// ---------------------------------------
gulp.task('demoApp',function(){
gulp.src( paths.jsDemoMain )
.pipe(gbrowserify({
debug: argv.env !== 'production',
insertGlobals : true,
transform: [
babelify.configure({
// optional: ["es7.asyncFunctions","runtime"]
})
],
}))
.pipe( // only minify in production
gulpif(argv.env === 'production', uglify({ compress:true, mangle:true}))
)
.on( "error", handleError)
.pipe(gulp.dest(paths.dest))
})
// watch files for live reload
gulp.task('watch',["watchify"],function(){
livereload.listen();
gulp.watch('./demo/build/**/*').on('change', livereload.changed);
gulp.watch('./demo/**/*.css').on('change', livereload.changed);
// gulp.watch( paths.html ).on('change', livereload.changed);
gulp.watch( 'scss/**/*.scss' ,['scss']);
});
/**
* ============= watchify to make it faster to compile
*/
gulp.task('watchify', function(){
return compile();
});
function compile(){
var w = watchify(
browserify({
entries: paths.jsDemoMain,
insertGlobals : true,
// debug: true,
cache: {}, packageCache: {},
})
.transform( babelify.configure({
// optional: ["es7.asyncFunctions","runtime"]
}))
)
function rebundle(){
w.bundle()
.on( "error", handleError)
.pipe(source( "app.demo.js"))
.pipe(gulp.dest(paths.dest));
// .pipe( livereload() );
}
w.on('update', function(args){
console.log('-> bundling...');
rebundle()
});
rebundle()
}
// ------------------------------server ------------------
gulp.task("js-es6",function(){
gulp.src([paths.jsLib])
.pipe( babel({
blacklist: ['regenerator','bluebirdCoroutines'],
// optional: ["es7.asyncFunctions"],
// only: __dirname+'/src/**/*.js',
}) )
.pipe( uglify({ compress:true, mangle:true}) )
.on( "error", handleError)
.pipe(gulp.dest("./lib"))
// .on('end', function() {
// fs.createWriteStream("./dist/.trigger");
// });
})
/**
* compile es6 code
*/
// gulp.task("watch-server",function(){
// gulp.watch([paths.jsLib,paths.jsShared], function ( event ) {
// console.log("server file changed >> "+ event.path.replace(__dirname,""))
// var destPath ="./dist/" + event.path.replace(__dirname+"/src/","").replace(/[^\/]+$/,"");
// console.log(destPath)
// return gulp.src( event.path )
// .pipe( babel({
// blacklist: ['regenerator','bluebirdCoroutines'],
// optional: ["es7.asyncFunctions"], // ,"runtime"
// only: __dirname+'/src/server/**/*.js',
// }) )
// .on( "error", handleError)
// .pipe(gulp.dest( destPath))
// .on('end', function() {
// fs.createWriteStream("./dist/.trigger");
// });
// });
// })
// ------------------------------ build ------------------
gulp.task('default',["js-es6"]);
gulp.task('build',['demoApp',"js-es6",'scss']);
gulp.task('serve',["js-es6",'watch']);
gulp.task("try",function(){
argv.env = "production";
gulp.run(["js-es6"])
})
// --------- utils ------------
function handleError(err) {
console.log(err.toString());
this.emit('end');
}