-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
57 lines (52 loc) · 1.41 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
const gulp = require('gulp');
const webpack = require('webpack');
const webpackStream = require('webpack-stream');
const rename = require('gulp-rename');
const watch = require('gulp-watch');
const uglify = require('gulp-uglify');
const exec = require('child_process').exec;
//
const srcFolder = "src/";
const files = ["index.js"];
const tasks = [];
function handleError(err) {
console.log(err.toString());
this.emit('end');
}
for (let i = 0; i < files.length; i++) {
const webpackConfig = {
module: {
loaders: [{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
query:{
presets:['es2015']
}
}]
}
};
gulp.task(files[i], function() {
return watch(srcFolder+"*", function() {
gulp.src(srcFolder+files[i])
.pipe(webpackStream(webpackConfig))
.on('error', handleError)
.pipe(rename(files[i], { extension: ".js" }))
.pipe(gulp.dest('build'))
.pipe(rename({suffix: ".min"}))
.pipe(uglify()) // minifies and uglifies the file
.on('error', handleError)
.pipe(gulp.dest('build'));
});
});
tasks.push(files[i]);
}
gulp.task('server', function (cb) {
exec('npm run start-server', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
tasks.push("server");
gulp.task("default", tasks);