-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
66 lines (56 loc) · 1.85 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
59
60
61
62
63
64
65
66
const gulp = require('gulp');
const gutil = require("gulp-util");
const webpack = require("webpack");
const babel = require('gulp-babel');
const sass = require('gulp-sass');
const WebpackDevServer = require("webpack-dev-server");
const webpackConfig = require("./webpack.config.js");
gulp.task("default",["lib-dev", "webpack-dev-server"]);
// Production build
gulp.task("build", ["webpack:build", "lib", "lib-styles"]);
gulp.task("webpack:build", function(callback) {
// modify some webpack config options
var myConfig = Object.create(webpackConfig);
// run webpack
webpack(myConfig, function(err, stats) {
if(err) throw new gutil.PluginError("webpack:build", err);
gutil.log("[webpack:build]", stats.toString({
colors: true
}));
callback();
});
});
gulp.task("lib", function(callback) {
return gulp.src("src/*.js")
.pipe(babel())
.pipe(gulp.dest("dist"));
});
gulp.task("lib-styles", function() {
return gulp.src("src/styles/*.scss")
.pipe(sass())
.pipe(gulp.dest("dist/styles"));
})
gulp.task("lib-dev", function(){
gulp.watch('src/*.js',['lib']);
gulp.watch('src/styles/*.scss',['lib-styles']);
});
// modify some webpack config options
const myDevConfig = Object.create(webpackConfig);
myDevConfig.devtool = "sourcemap";
myDevConfig.debug = true;
gulp.task("webpack-dev-server", function(callback) {
// modify some webpack config options
let 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");
});
});