-
Notifications
You must be signed in to change notification settings - Fork 106
/
gulpfile.js
105 lines (94 loc) · 2.94 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
// Gulp building scripts
var gulp = require("gulp");
var del = require("del");
var gutil = require("gulp-util");
var webpack = require("webpack");
var webpackConfig = require("./webpack.config.js");
var runSequence = require("run-sequence");
var Server = require('karma').Server;
var pkg = require("./package.json");
var dirs = pkg.configs.directories;
// ---------------------------------------------------------------------
// | Helper tasks |
// ---------------------------------------------------------------------
gulp.task("clean", function (done) {
del([ dirs.dist, dirs.coverage ]);
done();
});
gulp.task("webpack-dev", function(done) {
// modify some webpack config options
var webpackDevConfig = Object.create(webpackConfig);
webpackDevConfig.devtool = "sourcemap";
webpackDevConfig.debug = true;
// create a single instance of the compiler to allow caching
var webpackDevCompiler = webpack(webpackDevConfig);
// run webpack
webpackDevCompiler.run(function(err, stats) {
if(err) throw new gutil.PluginError("webpack:build-dev", err);
gutil.log("[webpack:build-dev]", stats.toString({
colors: true
}));
done();
});
});
gulp.task("webpack", function(done) {
// modify some webpack config options
var webpackProdConfig = Object.create(webpackConfig);
webpackProdConfig.plugins.push(new webpack.DefinePlugin({
"process.env": {
// This has effect on the react lib size
"NODE_ENV": JSON.stringify("production")
}
}), new webpack.optimize.UglifyJsPlugin());
webpackProdConfig.output.filename = "[name].min.js";
// run webpack
webpack(webpackProdConfig, function(err, stats) {
if(err) throw new gutil.PluginError("webpack:build", err);
gutil.log("[webpack:build]", stats.toString({
colors: true
}));
done();
});
});
gulp.task('test', function(done) {
// Be sure to return the stream
new Server({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, done).start();
});
gulp.task('test:coverage', function(done) {
// Be sure to return the stream
process.env.TEST_TYPE = "coverage";
new Server({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, done).start();
});
gulp.task('test:coveralls', function(done) {
// Be sure to return the stream
process.env.TEST_TYPE = "coveralls";
new Server({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, done).start();
});
// ---------------------------------------------------------------------
// | Main tasks |
// ---------------------------------------------------------------------
gulp.task("build-dev", function (done) {
runSequence(
"clean",
"test:coverage",
"webpack-dev",
done);
});
gulp.task("build", function (done) {
runSequence(
"clean",
"test:coveralls",
"webpack-dev",
"webpack",
done);
});
gulp.task("default", ["build"]);