-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
58 lines (55 loc) · 1.92 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
var Path = require('path');
var gulp = require('gulp');
var clean = require('gulp-clean');
var config = require('./resource/config.json');
/**************************
* webpack *
**************************/
gulp.task('webpack', function() {
var webpackConfig = require('./webpack.config');
var gulpWebpack = require('gulp-webpack');
var dir = Path.join('static', 'build');
return gulp.src(dir)
.pipe(clean())
.pipe(gulpWebpack(webpackConfig))
.pipe(gulp.dest(dir));
});
/**************************
* webpack-dev-server *
**************************/
gulp.task('webpack-dev-server', function() {
//start webpack develop server
var webpackConfig = require('./webpack.dev.config');
var WebpackDevServer = require('webpack-dev-server');
var webpack = require('webpack');
new WebpackDevServer(webpack(webpackConfig), {
contentBase: config.devServerUrl,
publicPath: webpackConfig.output.publicPath,
hot: true,
noInfo: false,
historyApiFallback: true,
proxy: { '*': config.devServerUrl }
}).listen(3000, 'localhost', function(err) {
if (err) console.log(err);
console.log('Listening at localhost:3000');
open('http://127.0.0.1:3000/webpack-dev-server/');
});
});
/**************************
* copy profiles *
**************************/
gulp.task('copyProfile', function() {
var allowEnv = ['dev', 'beta', 'prod'];
var env = process.argv[2] || allowEnv[0];
if (allowEnv.indexOf(env) === -1) {
env = allowEnv[0];
}
return gulp.src(Path.join(__dirname, 'profiles', env, '*'))
.pipe(gulp.dest(Path.join(__dirname, 'resource')));
});
/**************************
* Main *
**************************/
gulp.task('dev', ['copyProfile', 'webpack-dev-server']);
gulp.task('beta', ['webpack']);
gulp.task('prod', ['webpack']);