UNPKG

1.51 kBJavaScriptView Raw
1"use strict";
2var gulp = require('gulp');
3var babel = require('gulp-babel');
4var webpack = require('gulp-webpack');
5var plumber = require('gulp-plumber');
6var fse = require('fs-extra');
7var webpackCfg = require('./webpack.config');
8var webpackPubCfg = require('./webpack.pub');
9
10//后台代码编译成es5
11gulp.task('src', function() {
12 return gulp.src('src/**/*.*')
13 .pipe(plumber()) //plumber给pipe打补丁
14 .pipe(babel({
15 only: '*.js',
16 presets: ['es2015', "stage-0"],
17 plugins: ['transform-es2015-modules-commonjs']
18 }))
19 .pipe(gulp.dest('build'));
20});
21
22
23//前端代码编译
24gulp.task('webpack:watch', function() {
25 return gulp.src('web/src/app/app.jsx')
26 .pipe(webpack(webpackCfg))
27 .pipe(gulp.dest('web/build/app'));
28});
29gulp.task('webpack:publish', function() {
30 return gulp.src('web/src/app/app.jsx')
31 .pipe(webpack(webpackPubCfg))
32 .pipe(gulp.dest('web/build/app'));
33});
34
35gulp.task('web-dest', function() {
36 return gulp.src('web/src/**/+(*.html|*.ejs|*.css|*.eot|*.svg|*.ttf|*.woff)')
37 .pipe(gulp.dest('web/build'));
38});
39
40//监控
41gulp.task('watch', function() {
42 gulp.watch('web/src/**/*.*', ['web-dest']);
43 gulp.watch('./src/**/*.*', ['src']);
44});
45
46gulp.task('clean', function(cb) {
47 fse.emptyDirSync('./build');
48 fse.emptyDirSync('./web/build');
49 cb();
50});
51
52//编译文件
53gulp.task('publish', ["clean", "src", 'web-dest', 'webpack:publish']);
54
55gulp.task('build', ["src", 'web-dest', 'webpack:watch', "watch"]);
56
57process.on('uncaughtException', function(err) {
58 console.log(err);
59});
\No newline at end of file