Skip to content

Commit a4b19e5

Browse files
authored
perf: Optimize bundle packaging with Vite (parse-community#2553)
1 parent cfb25ef commit a4b19e5

16 files changed

+2689
-2784
lines changed

build_releases.js

+3-8
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ console.log(`Building JavaScript SDK v${pkg.version}...\n`)
3636

3737
console.log('Cleaning up old builds...\n');
3838

39-
rmDir(path.join(__dirname, 'dist'));
4039
rmDir(path.join(__dirname, 'lib'));
4140

4241
const crossEnv = 'npm run cross-env';
@@ -54,13 +53,9 @@ const gulp = 'npm run gulp';
5453
execCommand(`${crossEnv} PARSE_BUILD=react-native ${gulp} compile`),
5554
]);
5655

57-
console.log('Bundling and minifying for CDN distribution:');
56+
console.log('Bundling and minifying for CDN distribution');
5857
await Promise.all([
59-
execCommand(`${gulp} browserify`),
60-
execCommand(`${gulp} browserify-weapp`),
61-
]);
62-
await Promise.all([
63-
execCommand(`${gulp} minify`),
64-
execCommand(`${gulp} minify-weapp`),
58+
execCommand('npm run build:browser'),
59+
execCommand('npm run build:weapp'),
6560
]);
6661
}());

gulpfile.js

+4-99
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
const babel = require('gulp-babel');
2-
const browserify = require('browserify');
3-
const derequire = require('gulp-derequire');
42
const gulp = require('gulp');
5-
const insert = require('gulp-insert');
63
const path = require('path');
7-
const rename = require('gulp-rename');
8-
const source = require('vinyl-source-stream');
9-
const uglify = require('gulp-uglify');
104
const watch = require('gulp-watch');
115

126
const BUILD = process.env.PARSE_BUILD || 'browser';
13-
const VERSION = require('./package.json').version;
147

158
const transformRuntime = ["@babel/plugin-transform-runtime", {
169
"corejs": 3,
@@ -32,39 +25,14 @@ const PRESETS = {
3225
'react-native': ["@babel/preset-typescript", 'module:metro-react-native-babel-preset'],
3326
};
3427
const PLUGINS = {
35-
'browser': [transformRuntime, '@babel/plugin-proposal-class-properties', 'inline-package-json',
28+
'browser': [transformRuntime, '@babel/plugin-proposal-class-properties',
3629
['transform-inline-environment-variables', {'exclude': ['SERVER_RENDERING']}]],
37-
'weapp': [transformRuntime, '@babel/plugin-proposal-class-properties', 'inline-package-json',
30+
'weapp': [transformRuntime, '@babel/plugin-proposal-class-properties',
3831
['transform-inline-environment-variables', {'exclude': ['SERVER_RENDERING']}]],
39-
'node': ['inline-package-json', 'transform-inline-environment-variables'],
40-
'react-native': ['inline-package-json', 'transform-inline-environment-variables']
32+
'node': ['transform-inline-environment-variables'],
33+
'react-native': ['transform-inline-environment-variables']
4134
};
4235

43-
const DEV_HEADER = (
44-
'/**\n' +
45-
' * Parse JavaScript SDK v' + VERSION + '\n' +
46-
' *\n' +
47-
' * The source tree of this library can be found at\n' +
48-
' * https://github.com/ParsePlatform/Parse-SDK-JS\n' +
49-
' */\n'
50-
);
51-
52-
const FULL_HEADER = (
53-
'/**\n' +
54-
' * Parse JavaScript SDK v' + VERSION + '\n' +
55-
' *\n' +
56-
' * Copyright 2015-present Parse Platform\n' +
57-
' * All rights reserved.\n' +
58-
' *\n' +
59-
' * The source tree of this library can be found at\n' +
60-
' * https://github.com/ParsePlatform/Parse-SDK-JS\n' +
61-
' *\n' +
62-
' * This source code is licensed under the license found in the LICENSE\n' +
63-
' * file in the root directory of this source tree. Additional legal\n' +
64-
' * information can be found in the NOTICE file in the same directory.\n' +
65-
' */\n'
66-
);
67-
6836
function compileTask(stream) {
6937
return stream
7038
.pipe(babel({
@@ -82,69 +50,6 @@ gulp.task('compile', function() {
8250
return compileTask(gulp.src('src/*.*(js|ts)'));
8351
});
8452

85-
gulp.task('browserify', function(cb) {
86-
const stream = browserify({
87-
builtins: ['_process', 'events'],
88-
entries: 'lib/browser/Parse.js',
89-
standalone: 'Parse'
90-
})
91-
.exclude('xmlhttprequest')
92-
.ignore('_process')
93-
.bundle();
94-
stream.on('end', () => {
95-
cb();
96-
});
97-
return stream.pipe(source('parse.js'))
98-
.pipe(derequire())
99-
.pipe(insert.prepend(DEV_HEADER))
100-
.pipe(gulp.dest('./dist'));
101-
});
102-
103-
104-
gulp.task('browserify-weapp', function(cb) {
105-
const stream = browserify({
106-
builtins: ['_process', 'events'],
107-
entries: 'lib/weapp/Parse.js',
108-
standalone: 'Parse'
109-
})
110-
.exclude('xmlhttprequest')
111-
.ignore('_process')
112-
.bundle();
113-
stream.on('end', () => {
114-
cb();
115-
});
116-
return stream.pipe(source('parse.weapp.js'))
117-
.pipe(derequire())
118-
.pipe(insert.prepend(DEV_HEADER))
119-
.pipe(gulp.dest('./dist'));
120-
});
121-
122-
gulp.task('minify', function() {
123-
return gulp.src('dist/parse.js')
124-
.pipe(uglify())
125-
.pipe(insert.prepend(FULL_HEADER))
126-
.pipe(rename({ extname: '.min.js' }))
127-
.pipe(gulp.dest('./dist'))
128-
});
129-
130-
gulp.task('minify-weapp', function() {
131-
return gulp.src('dist/parse.weapp.js')
132-
.pipe(uglify())
133-
.pipe(insert.prepend(FULL_HEADER))
134-
.pipe(rename({ extname: '.min.js' }))
135-
.pipe(gulp.dest('./dist'))
136-
});
137-
13853
gulp.task('watch', function() {
139-
if (BUILD === 'browser') {
140-
const watcher = gulp.watch('src/*.*(js|ts)', { ignoreInitial: false }, gulp.series('compile', 'browserify', 'minify'));
141-
watcher.on('add', function(path) {
142-
console.log(`File ${path} was added`);
143-
});
144-
watcher.on('change', function(path) {
145-
console.log(`File ${path} was changed`);
146-
});
147-
return watcher;
148-
}
14954
return compileTask(watch('src/*.*(js|ts)', { ignoreInitial: false, verbose: true }));
15055
});

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = require('./lib/browser/Parse.js');
1+
module.exports = require('./lib/browser/Parse.js').default;

integration/test/ParseLegacyTest.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
const { Parse } = require('../../node');
4+
5+
describe('Parse Legacy Import', () => {
6+
it('can query object', async () => {
7+
const object = new Parse.Object('TestObject');
8+
object.set('foo', 'bar');
9+
await object.save();
10+
const query = new Parse.Query('TestObject');
11+
const result = await query.get(object.id);
12+
expect(result.id).toBe(object.id);
13+
});
14+
});

node.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = require('./lib/node/Parse.js');
1+
module.exports = require('./lib/node/Parse.js').default;

0 commit comments

Comments
 (0)