-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
81 lines (76 loc) · 2.17 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
const gulp = require('gulp');
const lazypipe = require('lazypipe');
const pump = require('pump');
const rename = require('gulp-rename');
const webpack = require('webpack');
const webpackStream = require('webpack-stream');
const uglify = require('gulp-uglify');
function webpackBuild(filename, libraryName, version) {
const config = {
module: {
loaders: [
{
//exclude: /node_modules/,
test: /\.js$/,
loader: 'babel',
query: {
presets: ['es2015'],
plugins: ['transform-flow-strip-types', "dynamic-import-webpack"]
}
},
{
test: /\.json$/,
loader: 'json'
}
]
},
node: {
// Mock Node.js modules that Babel require()s but that we don't
// particularly care about.
fs: 'empty',
module: 'empty',
net: 'empty'
},
output: {
filename: filename,
library: libraryName,
libraryTarget: 'umd'
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"',
BABEL_VERSION: JSON.stringify(require('babel-core/package.json').version),
VERSION: JSON.stringify(version)
}),
// // Use browser version of visionmedia-debug
// new webpack.NormalModuleReplacementPlugin(
// /..\/..\/package/,
// '../../../../src/babel-package-shim'
// ),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.DedupePlugin()
]
};
if (libraryName !== 'Babel') {
// This is a secondary package (eg. Babili), we should expect that Babel
// was already loaded, rather than bundling it in here too.
config.externals = {
'babel-standalone': 'babelPresetEnv',
};
}
return webpackStream(config);
}
const minifyAndRename = lazypipe()
.pipe(uglify)
.pipe(rename, { extname: '.min.js' });
gulp.task('default', ['build']);
gulp.task('build', ['build-babel']);
gulp.task('build-babel', cb => {
pump([
gulp.src('src/index.js'),
webpackBuild('babel-preset-env.js', 'babelPresetEnv', require('./package.json').version),
gulp.dest('.'),
minifyAndRename(),
gulp.dest('.'),
], cb);
});