-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
119 lines (103 loc) · 3.01 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//import path from "path";
var path = require("path");
var gulp = require("gulp");
var babel = require('gulp-babel');
var mocha = require('gulp-mocha');
var gutil = require("gulp-util");
var webpack = require("webpack");
var WebpackDevServer = require('webpack-dev-server');
var webpackConfig =
{
entry: {
preload: path.join(__dirname, "source", "main.js"), // './target/main.js'
},
devtool: "source-map",
output: {
path: path.join(__dirname, "build"),
publicPath: '../build/',
filename: '[name].orb.js',
chunkFilename: '[id].orb.js'
},
module: {
loaders: [{
test: /\.js$/,
loader: "babel-loader",
include: [
path.join(__dirname, "source"),
],
exclude: /(node_modules|bower_components)/,
query: {
presets: ['es2015']
}
}],
},
};
function buildJs (options, callback) {
var plugins = options.minify ? [
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
},
output: {
comments: false,
semicolons: true,
},
}),
] : [];
var myConfig = Object.create(webpackConfig);
myConfig.plugins = plugins;
myConfig.bail = !options.watch;
myConfig.watch = options.watch;
webpack(myConfig,
function (error, stats) {
if ( error ) {
var pluginError = new gutil.PluginError("webpack", error);
if ( callback ) {
callback(pluginError);
} else {
gutil.log("[webpack]", pluginError);
}
return;
}
gutil.log("[webpack]", stats.toString());
if (callback) { callback(); }
});
}
gulp.task("js:es6", function (callback) {
buildJs({ watch: false, minify: false }, callback);
});
gulp.task("js:es6:minify", function (callback) {
buildJs({ watch: false, minify: true }, callback);
});
/*
gulp.task("watch", function () {
buildJs({ watch: true, minify: false });
});
*/
gulp.task('test', ['js:es6'], function () {
return gulp.src('test/*.js')
.pipe(mocha())
.on('error', function () {
gulp.emit('end');
});
});
gulp.task('watch', function () {
return gulp.watch(['source/**', 'test/**'], ['js:es6']);
});
gulp.task('server', ['js:es6'], 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
},
hot: true
}).listen(8080, 'localhost', function(err) {
if(err) throw new gutil.PluginError('webpack-dev-server', err);
gutil.log('[webpack-dev-server]', 'http://localhost:8080/public/index.html');
});
});