Skip to content

perf: Optimize bundle packaging with Vite #2553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions build_releases.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ console.log(`Building JavaScript SDK v${pkg.version}...\n`)

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

rmDir(path.join(__dirname, 'dist'));
rmDir(path.join(__dirname, 'lib'));

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

console.log('Bundling and minifying for CDN distribution:');
console.log('Bundling and minifying for CDN distribution');
await Promise.all([
execCommand(`${gulp} browserify`),
execCommand(`${gulp} browserify-weapp`),
]);
await Promise.all([
execCommand(`${gulp} minify`),
execCommand(`${gulp} minify-weapp`),
execCommand('npm run build:browser'),
execCommand('npm run build:weapp'),
]);
}());
103 changes: 4 additions & 99 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
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,
Expand All @@ -32,39 +25,14 @@ const PRESETS = {
'react-native': ["@babel/preset-typescript", 'module:metro-react-native-babel-preset'],
};
const PLUGINS = {
'browser': [transformRuntime, '@babel/plugin-proposal-class-properties', 'inline-package-json',
'browser': [transformRuntime, '@babel/plugin-proposal-class-properties',
['transform-inline-environment-variables', {'exclude': ['SERVER_RENDERING']}]],
'weapp': [transformRuntime, '@babel/plugin-proposal-class-properties', 'inline-package-json',
'weapp': [transformRuntime, '@babel/plugin-proposal-class-properties',
['transform-inline-environment-variables', {'exclude': ['SERVER_RENDERING']}]],
'node': ['inline-package-json', 'transform-inline-environment-variables'],
'react-native': ['inline-package-json', 'transform-inline-environment-variables']
'node': ['transform-inline-environment-variables'],
'react-native': ['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 2015-present Parse Platform\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' +
' *\n' +
' * This source code is licensed under the license found in the LICENSE\n' +
' * file in the root directory of this source tree. Additional legal\n' +
' * information can be found in the NOTICE file in the same directory.\n' +
' */\n'
);

function compileTask(stream) {
return stream
.pipe(babel({
Expand All @@ -82,69 +50,6 @@ gulp.task('compile', function() {
return compileTask(gulp.src('src/*.*(js|ts)'));
});

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() {
if (BUILD === 'browser') {
const watcher = gulp.watch('src/*.*(js|ts)', { ignoreInitial: false }, gulp.series('compile', 'browserify', 'minify'));
watcher.on('add', function(path) {
console.log(`File ${path} was added`);
});
watcher.on('change', function(path) {
console.log(`File ${path} was changed`);
});
return watcher;
}
return compileTask(watch('src/*.*(js|ts)', { ignoreInitial: false, verbose: true }));
});
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('./lib/browser/Parse.js');
module.exports = require('./lib/browser/Parse.js').default;
14 changes: 14 additions & 0 deletions integration/test/ParseLegacyTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

const { Parse } = require('../../node');

describe('Parse Legacy Import', () => {
it('can query object', async () => {
const object = new Parse.Object('TestObject');
object.set('foo', 'bar');
await object.save();
const query = new Parse.Query('TestObject');
const result = await query.get(object.id);
expect(result.id).toBe(object.id);
});
});
2 changes: 1 addition & 1 deletion node.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('./lib/node/Parse.js');
module.exports = require('./lib/node/Parse.js').default;
Loading