-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
93 lines (80 loc) · 2.56 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
var gulp = require('gulp');
var gutil = require('gulp-util');
var webpack = require('webpack');
var Server = require('karma').Server;
var webpackExample = require('./webpack/webpack-dev.config');
var webpackModule = require('./webpack/webpack.config');
var open = require('gulp-open');
var del = require('del');
var internalIP = require('internal-ip');
var babel = require('gulp-babel');
var path = require('path');
var runSequence = require('gulp-run-sequence');
var config = require('./package.json');
var error = function(e) {
console.error(e);
if (e.stack) {
console.error(e.stack);
}
process.exit(1);
};
gulp.task('karma', function(done) {
new Server({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, done).start();
});
gulp.task('open', function() {
gulp.src(__filename)
.pipe(open({ uri: "http://" + ('127.0.0.1') + ":8888/index.html" }));
});
gulp.task('hot', function(callback) {
webpackExample.server();
});
gulp.task('webpack-module', function(done) {
webpack(Object.create(webpackModule)).run(function(err, stats) {
if (err) throw new gutil.PluginError("webpack-module", err);
gutil.log("[webpack]", stats.toString({
// output options
}));
done();
});
});
gulp.task('webpack-example', function(done) {
var wbpk = Object.create(webpackExample.build);
wbpk.output.path = path.join(process.cwd(), 'examples/dist');
webpack(wbpk).run(function(err, stats) {
if (err) throw new gutil.PluginError("webpack-example", err);
gutil.log("[webpack]", stats.toString({
// output options
}));
done();
});
});
gulp.task('min-webpack', function(done) {
var wbpk = Object.create(webpackModule);
wbpk.output.filename = '[name].min.js';
wbpk.plugins.push(new webpack.optimize.UglifyJsPlugin());
webpack(wbpk).run(function(err, stats) {
if (err) throw new gutil.PluginError("min-webpack", err);
gutil.log("[webpack]", stats.toString({
// output options
}));
done();
});
});
gulp.task('babel', function(done) {
return gulp.src('src/**/*.js')
.pipe(babel())
.pipe(gulp.dest('lib'));
});
gulp.task('watch', function() {
gulp.watch(['./lib/**/*.*'], ['demo']);
});
gulp.task('default', function(cb) {
runSequence('babel', 'webpack-module', 'webpack-example', cb);
});
//gulp.task('default', ['babel', 'webpack-module','webpack-example']);
gulp.task('test', ['karma']);
gulp.task('demo', ['hot', 'open']);
gulp.task('min', ['min-webpack']);