-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
114 lines (98 loc) · 2.71 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
"use strict";
Object.assign = require('object.assign');
var fs = require('fs');
var path = require('path');
var gulp = require('gulp');
var autoprefixer = require('gulp-autoprefixer');
var extReplace = require('gulp-ext-replace');
var watch = require('gulp-watch');
var babel = require('gulp-babel');
var connect = require('gulp-connect');
var sass = require('gulp-sass');
var deploy = require('gulp-gh-pages');
var React = require('react');
var webpack = require('webpack');
var gulpWebpack = require('gulp-webpack');
var PRODUCTION = (process.env.NODE_ENV === 'production');
var gulpPlugins = [];
if (PRODUCTION) {
gulpPlugins.push(new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("production")
}
}));
gulpPlugins.push(new webpack.optimize.DedupePlugin());
gulpPlugins.push(new webpack.optimize.UglifyJsPlugin({
compress: true,
mangle: true,
sourceMap: true
}));
}
var webpackConfig = {
cache: true,
debug: !PRODUCTION,
devtool: PRODUCTION ? 'source-map' : 'eval-source-map',
context: __dirname,
output: {
path: path.resolve('./example/build/'),
filename: 'index.js'
},
module: {
loaders: [
{
test: /\.jsx|.js$/,
exclude: /node_modules\//,
loaders: [
'babel-loader?stage=1'
]
},
]
},
resolve: {
extensions: ['', '.js', '.jsx']
},
plugins: gulpPlugins
};
gulp.task('build-dist-js', function() {
// build javascript files
return gulp.src('src/**/*.{js,jsx}')
.pipe(babel({
stage: 1
}))
.pipe(extReplace('.js'))
.pipe(gulp.dest('dist'));
});
gulp.task('build-example-js', function() {
var compiler = gulpWebpack(webpackConfig, webpack);
return gulp.src('./example/js/index.js')
.pipe(compiler)
.pipe(gulp.dest('./example/build'));
});
gulp.task('watch-example-js', function() {
var compiler = gulpWebpack(Object.assign({}, {watch: true}, webpackConfig), webpack);
return gulp.src('./example/js/index.js')
.pipe(compiler)
.pipe(gulp.dest('./example/build'));
});
gulp.task('build-example', function() {
// setup babel hook
require("babel/register")({
stage: 1
});
var Index = React.createFactory(require('./example/base.jsx'));
var markup = '<!document html>' + React.renderToString(Index());
// write file
fs.writeFileSync('./example/index.html', markup);
});
gulp.task('example-server', function() {
connect.server({
root: 'example',
port: '9989'
});
});
gulp.task('build', ['build-dist-js', 'build-example', 'build-example-js']);
gulp.task('develop', ['build-example', 'watch-example-js', 'example-server']);
gulp.task('deploy-example', ['build'], function() {
return gulp.src('./example/**/*')
.pipe(deploy());
});