forked from facebookarchive/flux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gulpfile.js
113 lines (102 loc) · 2.47 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
var babel = require('gulp-babel');
var del = require('del');
var flatten = require('gulp-flatten');
var gulp = require('gulp');
var gulpUtil = require('gulp-util');
var runSequence = require('run-sequence');
var source = require('vinyl-source-stream');
var webpackStream = require('webpack-stream');
var babelDefaultOptions = require('./scripts/babel/default-options');
var paths = {
dist: './dist/',
flowInclude: 'flow/include',
lib: 'lib',
entry: './index.js',
src: [
'src/**/*.js',
'!src/**/__tests__/**/*.js',
'!src/**/__mocks__/**/*.js',
],
};
var buildDist = function(opts) {
var webpackOpts = {
debug: opts.debug,
module: {
loaders: [
{test: /\.js$/, loader: 'babel'}
],
},
output: {
filename: opts.output,
libraryTarget: 'umd',
library: 'Flux'
},
plugins: [
new webpackStream.webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(
opts.debug ? 'development' : 'production'
),
})
]
};
if (!opts.debug) {
webpackOpts.plugins.push(
new webpackStream.webpack.optimize.UglifyJsPlugin({
compress: {
hoist_vars: true,
screw_ie8: true,
warnings: false
}
})
);
}
return webpackStream(webpackOpts, null, function(err, stats) {
if (err) {
throw new gulpUtil.PluginError('webpack', err);
}
if (stats.compilation.errors.length) {
gulpUtil.log('webpack', '\n' + stats.toString({colors: true}));
}
});
};
gulp.task('clean', function(cb) {
del([paths.lib, paths.flowInclude, 'Flux.js'], cb);
});
gulp.task('lib', function() {
return gulp
.src(paths.src)
.pipe(babel(babelDefaultOptions))
.pipe(flatten())
.pipe(gulp.dest(paths.lib));
});
gulp.task('flow', function() {
return gulp
.src(paths.src)
.pipe(flatten())
.pipe(gulp.dest(paths.flowInclude));
});
gulp.task('dist', ['lib'], function() {
var distOpts = {
debug: true,
output: 'Flux.js'
};
return gulp
.src(paths.entry)
.pipe(buildDist(distOpts))
.pipe(gulp.dest(paths.dist));
});
gulp.task('dist:min', ['lib'], function() {
var distOpts = {
debug: false,
output: 'Flux.min.js'
};
return gulp
.src(paths.entry)
.pipe(buildDist(distOpts))
.pipe(gulp.dest(paths.dist));
});
gulp.task('build', ['lib', 'flow', 'dist']);
gulp.task('publish', function(cb) {
runSequence('clean', 'flow', 'dist', 'dist:min', cb);
});
gulp.task('default', ['build']);