-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathGulpfile.js
57 lines (45 loc) · 1.52 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
var gulp = require('gulp');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps');
var gutil = require("gulp-util");
var webpack = require("webpack");
var WebpackDevServer = require("webpack-dev-server");
var webpackConfig = require("./webpack.config.js");
var stream = require('webpack-stream');
gulp.task('webpack', [], function() {
return gulp.src(path.ALL)
.pipe(sourcemaps.init())
.pipe(stream(webpackConfig))
.pipe(uglify())
.pipe(sourcemaps.write())
.pipe(gulp.dest(path.DEST_BUILD));
});
gulp.task("webpack-dev-server", function(callback) {
// modify some webpack config options
var myConfig = Object.create(webpackConfig);
myConfig.devtool = "eval";
myConfig.debug = true;
// Start a webpack-dev-server
new WebpackDevServer(webpack(myConfig), {
publicPath: "/" + myConfig.output.publicPath,
stats: {
colors: true
}
}).listen(8080, "localhost", function(err) {
if (err) throw new gutil.PluginError("webpack-dev-server", err);
gutil.log("[webpack-dev-server]", "http://localhost:8080/webpack-dev-server/index.html");
});
});
var path = {
HTML: 'src/index.html',
ALL: ['src/**/*.jsx', 'src/**/*.js'],
MINIFIED_OUT: 'build.min.js',
DEST_SRC: 'dist/src',
DEST_BUILD: 'dist/build',
DEST: 'dist'
};
gulp.task('watch', function() {
gulp.watch(path.ALL, ['webpack']);
});
gulp.task('default', ['webpack-dev-server', 'watch']);