-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
44 lines (40 loc) · 1.11 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
const gulp = require('gulp');
const sourcemaps = require('gulp-sourcemaps');
const babel = require('gulp-babel');
const concat = require('gulp-concat');
const clean = require('gulp-clean');
const webpack = require('webpack');
const webpackConfig = require('./webpack.config');
const webpackDevServer = require('webpack-dev-server');
gulp.task('clean', ()=>{
gulp.src('./dist/**/*.js', {read: false})
.pipe(clean());
});
gulp.task('webpack', ()=>{
webpack(webpackConfig, (err, stats)=>{
if(err){
throw err;
}
console.log('webpack complete.');
});
});
// 为webpack提供了一个静态文件服务器
gulp.task('server', ['webpack'], ()=>{
new webpackDevServer(webpack(webpackConfig), {
publicPath: '/' + webpackConfig.output.publicPath,
stats: {
colors: true
},
hot: true
}).listen(9014, 'localhost', (err)=>{
if(err){
throw err;
}else{
console.log('[webpack-dev-server]', 'http://localhost:9014/webpack-dev-server/index.html');
}
});
})
gulp.task('dev', ['clean','webpack'], ()=>{
gulp.watch('./src/**/*.js', ['clean','webpack']);
});
gulp.task('default', ['clean','webpack','server','dev']);