-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
136 lines (121 loc) · 3.49 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/**
* Based on the work of
* Nestor Hernandez Ojeda (Phasersito)
*/
var gulp = require('gulp');
var gutil = require('gulp-util');
var zip = require('gulp-zip');
var localtunnel = require('localtunnel');
var path = require('path');
var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var karma = require('karma').server;
var plato = require('gulp-plato');
// WebPack configuration
var webpackConfig = require('./webpack.config.js');
gulp.task('default', ['development']);
gulp.task('build', function(callback) {
var myConfig = Object.create(webpackConfig);
myConfig.plugins = myConfig.plugins.concat(
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production')
}
}),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin()
);
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('development', function(callback) {
var myConfig = Object.create(webpackConfig);
myConfig.devtool = 'eval';
myConfig.debug = true;
new WebpackDevServer(webpack(myConfig), {
contentBase: path.join(__dirname, './build'),
stats: {
colors: true
}
}).listen(8080, 'localhost', function(err) {
if (err) throw new gutil.PluginError('webpack-dev-server', err);
gutil.log('[dev-server]', 'http://localhost:8080/ -> Root');
gutil.log('[dev-server]', 'http://localhost:8080/webpack-dev-server/ -> with LiveReload');
});
});
gulp.task('serve-ie9', function(callback) {
var myConfig = Object.create(webpackConfig);
myConfig.devtool = 'eval';
myConfig.debug = true;
new WebpackDevServer(webpack(myConfig), {
contentBase: path.join(__dirname, './build'),
stats: {
colors: true
}
}).listen(8080, '0.0.0.0', function(err) {
if (err) throw new gutil.PluginError('webpack-dev-server', err);
gutil.log('[dev-server]', 'http://localhost:8080/ -> Root');
gutil.log('[dev-server]', 'http://localhost:8080/webpack-dev-server/ -> with LiveReload');
});
});
gulp.task('localtunnel', function(callback) {
localtunnel(8080, function(err, tunnel) {
if (err) throw new gutil.PluginError('localtunnel', err);
var myConfig = Object.create(webpackConfig);
myConfig.devtool = 'eval';
myConfig.debug = true;
new WebpackDevServer(webpack(myConfig), {
contentBase: path.join(__dirname, './build'),
stats: {
colors: true
}
}).listen(8080, 'localhost', function(err) {
if (err) throw new gutil.PluginError('webpack-dev-server', err);
gutil.log('[localtunnel]', tunnel.url + ' -> Root');
gutil.log('[localtunnel]', tunnel.url + '/webpack-dev-server/ -> with LiveReload');
});
});
});
gulp.task('cocoon', ['build'], function(callback) {
return gulp.src('./build/**/*')
.pipe(zip('dist.zip'))
.pipe(gulp.dest('./build'));
});
gulp.task('test', function(done) {
karma.start({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, done);
});
gulp.task('tdd', function(done) {
karma.start({
configFile: __dirname + '/karma.conf.js',
singleRun: false,
autoWatch: true
}, done);
});
gulp.task('travis', function(done) {
karma.start({
configFile: __dirname + '/karma.conf.js',
singleRun: true,
browsers: ['Firefox']
}, done);
});
gulp.task('plato', function() {
return gulp.src('./src/**/*.js')
.pipe(plato('reports/plato/', {
jshint: {
options: {
strict: true
}
},
complexity: {
trycatch: true
}
}));
});