forked from future-challenger/petshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
66 lines (59 loc) · 1.89 KB
/
gulpfile.babel.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
/**
* Created by Uncle Charlie, 2017/01/18
*/
import gulp from 'gulp'
import eslint from 'gulp-eslint'
import babel from 'gulp-babel'
import gutil from "gulp-util";
import sourcemaps from 'gulp-sourcemaps'
import gulpWebpack from 'webpack-stream'
import webpack from 'webpack'
import webpackConfig from './webpack.config'
const paramConfig = {
source: 'server/**/*.js',
clientSource: 'client/H5/index.js',
serverDest: './built/server',
clientDest: './built/client/assets',
}
gulp.task('lint', () => {
return gulp.src([paramConfig.source, '!node_modules/**', '!server/petshop-admin/**', '!server/node_modules/**'])
.pipe(eslint())
.pipe(eslint.result(result => {
console.log(`ESLint result: ${result.filePath}`);
console.log(`# Messages: `, result.messages);
console.log(`# Warnings: ${result.warningCount}`);
console.log(`# Errors: ${result.errorCount}`);
}))
.pipe(eslint.format())
.pipe(eslint.failOnError())
})
gulp.task('babel', () => {
return gulp.src(paramConfig.source)
.pipe(babel())
.pipe(gulp.dest(paramConfig.serverDest))
})
gulp.task('babel-sourcemaps', () => {
return gulp.src(paramConfig.source)
.pipe(sourcemaps.init())
.pipe(babel())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(paramConfig.serverDest))
})
gulp.task('webpack:build', (callback) => {
let config = Object.create(webpackConfig)
// return gulp.src(paramConfig.clientSource)
// .pipe(gulpWebpack({}, webpack))
// .pipe(gulpWebpack(require('./webpack.config.js')))
// .pipe(gulp.dest(paramConfig.clientDest))
webpack(config, (err, stats) => {
if (err) throw new gutil.PluginError('webpack:build', err)
gutil.log('[webpack:util]', stats.toString({
colors: true
}))
if (callback)
callback()
})
})
gulp.task('default', [/*'lint', */'babel-sourcemaps', 'webpack:build'], () => {
console.log('#####gulp default task!')
})