forked from parse-community/Parse-SDK-JS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
144 lines (132 loc) · 4.41 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
const babel = require('gulp-babel');
const browserify = require('browserify');
const derequire = require('gulp-derequire');
const gulp = require('gulp');
const insert = require('gulp-insert');
const path = require('path');
const rename = require('gulp-rename');
const source = require('vinyl-source-stream');
const uglify = require('gulp-uglify');
const watch = require('gulp-watch');
const BUILD = process.env.PARSE_BUILD || 'browser';
const VERSION = require('./package.json').version;
const transformRuntime = ["@babel/plugin-transform-runtime", {
"corejs": 3,
"helpers": true,
"regenerator": true,
"useESModules": false
}];
const PRESETS = {
'browser': [["@babel/preset-env", {
"targets": "> 0.25%, not dead"
}], '@babel/preset-react'],
'weapp': [["@babel/preset-env", {
"targets": "> 0.25%, not dead"
}], '@babel/preset-react'],
'node': [["@babel/preset-env", {
"targets": { "node": "8" }
}]],
'react-native': ['module:metro-react-native-babel-preset'],
};
const PLUGINS = {
'browser': [transformRuntime, '@babel/plugin-transform-flow-comments', '@babel/plugin-proposal-class-properties', 'inline-package-json',
['transform-inline-environment-variables', {'exclude': ['SERVER_RENDERING']}]],
'weapp': [transformRuntime, '@babel/plugin-transform-flow-comments', '@babel/plugin-proposal-class-properties', 'inline-package-json',
['transform-inline-environment-variables', {'exclude': ['SERVER_RENDERING']}]],
'node': ['@babel/plugin-transform-flow-comments', 'inline-package-json', 'transform-inline-environment-variables'],
'react-native': ['@babel/plugin-transform-flow-comments', 'inline-package-json', 'transform-inline-environment-variables']
};
const DEV_HEADER = (
'/**\n' +
' * Parse JavaScript SDK v' + VERSION + '\n' +
' *\n' +
' * The source tree of this library can be found at\n' +
' * https://github.com/ParsePlatform/Parse-SDK-JS\n' +
' */\n'
);
const FULL_HEADER = (
'/**\n' +
' * Parse JavaScript SDK v' + VERSION + '\n' +
' *\n' +
' * Copyright (c) 2015-present, Parse, LLC.\n' +
' * All rights reserved.\n' +
' *\n' +
' * The source tree of this library can be found at\n' +
' * https://github.com/ParsePlatform/Parse-SDK-JS\n' +
' * This source code is licensed under the BSD-style license found in the\n' +
' * LICENSE file in the root directory of this source tree. An additional grant\n' +
' * of patent rights can be found in the PATENTS file in the same directory.\n' +
' */\n'
);
gulp.task('compile', function() {
return gulp.src('src/*.js')
.pipe(babel({
presets: PRESETS[BUILD],
plugins: PLUGINS[BUILD],
}))
// Second pass to kill BUILD-switched code
.pipe(babel({
plugins: ['minify-dead-code-elimination'],
}))
.pipe(gulp.dest(path.join('lib', BUILD)));
});
gulp.task('browserify', function(cb) {
const stream = browserify({
builtins: ['_process', 'events'],
entries: 'lib/browser/Parse.js',
standalone: 'Parse'
})
.exclude('xmlhttprequest')
.ignore('_process')
.bundle();
stream.on('end', () => {
cb();
});
return stream.pipe(source('parse.js'))
.pipe(derequire())
.pipe(insert.prepend(DEV_HEADER))
.pipe(gulp.dest('./dist'));
});
gulp.task('browserify-weapp', function(cb) {
const stream = browserify({
builtins: ['_process', 'events'],
entries: 'lib/weapp/Parse.js',
standalone: 'Parse'
})
.exclude('xmlhttprequest')
.ignore('_process')
.bundle();
stream.on('end', () => {
cb();
});
return stream.pipe(source('parse.weapp.js'))
.pipe(derequire())
.pipe(insert.prepend(DEV_HEADER))
.pipe(gulp.dest('./dist'));
});
gulp.task('minify', function() {
return gulp.src('dist/parse.js')
.pipe(uglify())
.pipe(insert.prepend(FULL_HEADER))
.pipe(rename({ extname: '.min.js' }))
.pipe(gulp.dest('./dist'))
});
gulp.task('minify-weapp', function() {
return gulp.src('dist/parse.weapp.js')
.pipe(uglify())
.pipe(insert.prepend(FULL_HEADER))
.pipe(rename({ extname: '.min.js' }))
.pipe(gulp.dest('./dist'))
});
gulp.task('watch', function() {
return watch('src/*.js', { ignoreInitial: false, verbose: true })
.pipe(babel({
presets: PRESETS[BUILD],
plugins: PLUGINS[BUILD],
}))
// Second pass to kill BUILD-switched code
.pipe(babel({
plugins: ['minify-dead-code-elimination'],
}))
.pipe(gulp.dest(path.join('lib', BUILD)));
});