-
Notifications
You must be signed in to change notification settings - Fork 13
/
gulpfile.js
91 lines (79 loc) · 2.37 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
var del = require('del');
var envify = require('gulp-envify');
var gulp = require('gulp');
var gutil = require('gutil');
var path = require('path');
var runSequence = require('run-sequence');
var template = require('gulp-template');
var uglify = require('gulp-uglify');
var webpack = require('webpack');
var renderOnServer = require('./src/server');
gulp.task('webpack', function(callback) {
// run webpack
webpack({
entry: {
app: './src/client.js',
vendor: ['alloyeditor', 'react', 'react-dom'],
},
output: {
filename: './dist/bundle.js'
},
module: {
context: path.join(__dirname, 'node_modules'),
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel',
query: {
presets: ['react', 'es2015']
}
}
]
},
plugins: [
new webpack.optimize.CommonsChunkPlugin('vendor', './dist/vendor.bundle.js')
]
}, function(err) {
if (err) {
throw new gutil.PluginError('webpack', err);
}
callback();
});
});
gulp.task('build', function(callback) {
runSequence('clean', ['webpack', 'copy-alloyeditor', 'render-on-server'], callback);
});
gulp.task('clean', function(callback) {
del('./dist')
.then(function() {
callback();
});
});
gulp.task('copy-alloyeditor', function() {
return gulp.src(['./node_modules/alloyeditor/dist/alloy-editor/**/*'])
.pipe(gulp.dest('./dist/alloyeditor'));
});
gulp.task('default', function(callback) {
runSequence(['build'], callback);
});
gulp.task('minimize', function() {
return gulp.src(['dist/bundle.js', 'dist/vendor.bundle.js'])
.pipe(envify())
.pipe(uglify())
.pipe(gulp.dest('dist'));
});
gulp.task('render-on-server', function () {
return gulp.src('src/index.html')
.pipe(template({
content: renderOnServer()
}))
.pipe(gulp.dest('dist'));
});
gulp.task('release', function(callback) {
process.env.NODE_ENV = 'production';
runSequence('build', 'minimize', callback);
});
gulp.task('watch', ['build'], function(callback) {
gulp.watch('src/**/*', ['build'], callback);
});