This repository has been archived by the owner on May 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathgulpfile.babel.js
80 lines (74 loc) · 1.84 KB
/
gulpfile.babel.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
import gulp from 'gulp';
import babel from 'gulp-babel';
import runSequence from 'run-sequence';
import webpackStream from 'webpack-stream';
import del from 'del';
const buildDist = (opts) => {
const webpackOpts = {
debug: opts.debug,
externals: {
React: 'React',
'draft-js': 'Draft'
},
output: {
filename: opts.output,
libraryTarget: 'var',
library: 'DraftTypeahead'
},
plugins: [
new webpackStream.webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(
opts.debug ? 'development' : 'production'
)
}),
new webpackStream.webpack.optimize.OccurenceOrderPlugin(),
new webpackStream.webpack.optimize.DedupePlugin()
]
};
if (!opts.debug) {
webpackOpts.plugins.push(
new webpackStream.webpack.optimize.UglifyJsPlugin({
compress: {
screw_ie8: true
}
})
);
}
return webpackStream(webpackOpts, null, (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', () => {
return del(['dist', 'lib']);
});
gulp.task('modules', () => {
return gulp.src('src/index.js')
.pipe(babel())
.pipe(gulp.dest('lib'));
});
gulp.task('dist', ['modules'], () => {
const opts = {
debug: true,
output: 'draft-typeahead.js'
};
return gulp.src('lib/index.js')
.pipe(buildDist(opts))
.pipe(gulp.dest('dist'));
});
gulp.task('dist:min', ['modules'], () => {
const opts = {
debug: false,
output: 'draft-typeahead.min.js'
};
return gulp.src('lib/index.js')
.pipe(buildDist(opts))
.pipe(gulp.dest('dist'));
});
gulp.task('default', (cb) => {
runSequence('clean', 'modules', ['dist', 'dist:min'], cb);
});