Skip to content

Commit

Permalink
Merge pull request #1369 from ably/esbuild
Browse files Browse the repository at this point in the history
build: use esbuild for web bundles
  • Loading branch information
owenpearson authored Jul 19, 2023
2 parents 8e9d1c8 + 4d22ee2 commit c508a39
Show file tree
Hide file tree
Showing 11 changed files with 649 additions and 85 deletions.
1 change: 0 additions & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@ jobs:
- run: npm ci
- run: npm run lint
- run: npm run format:check
- run: npm run check-closure-compiler
- run: npx tsc --noEmit ably.d.ts build/ably-webworker.min.d.ts
- run: npm audit --production
5 changes: 2 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
4. Commit your changes (`git commit -am 'Add some feature'`)
5. Ensure you have added suitable tests and the test suite is passing(`npm test`)
6. Ensure the [type definitions](https://github.com/ably/ably-js/blob/main/ably.d.ts) have been updated if the public API has changed
7. Ensure you stick to the version of JS used by the library (currently ES5). (The minfication task (`npm run grunt -- closureCompiler:ably.js`) will enforce that you stick to ES5 syntax, but will not enforce that you don't use, for example, new methods)
8. Push the branch (`git push origin my-new-feature`)
9. Create a new Pull Request
7. Push the branch (`git push origin my-new-feature`)
8. Create a new Pull Request

## Release Process

Expand Down
66 changes: 43 additions & 23 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
var fs = require('fs');
var path = require('path');
var webpackConfig = require('./webpack.config');
var esbuild = require('esbuild');
var umdWrapper = require('esbuild-plugin-umd-wrapper');
var banner = require('./src/fragments/license');

module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-closure-tools');
grunt.loadNpmTasks('grunt-bump');
grunt.loadNpmTasks('grunt-webpack');

Expand All @@ -16,7 +18,6 @@ module.exports = function (grunt) {
fragments: 'src/platform/web/fragments',
static: 'build',
dest: 'build',
tools_compiler: __dirname + '/node_modules/google-closure-compiler/compiler.jar',
};

function compilerSpec(src, dest) {
Expand Down Expand Up @@ -51,24 +52,6 @@ module.exports = function (grunt) {
},
};

gruntConfig['closureCompiler'] = {
options: {
compilerFile: dirs.tools_compiler,
compilerOpts: {
compilation_level: 'SIMPLE_OPTIMIZATIONS',
/* By default, the compiler assumes you're using es6 and transpiles to
* es5, adding various (unnecessary and undesired) polyfills. Specify
* both in and out to es5 to avoid transpilation */
language_in: 'ECMASCRIPT5',
language_out: 'ECMASCRIPT5',
strict_mode_input: true,
checks_only: true,
warning_level: 'QUIET',
},
},
'ably.js': compilerSpec('<%= dirs.static %>/ably.js'),
};

gruntConfig.bump = {
options: {
files: ['package.json', 'README.md'],
Expand Down Expand Up @@ -106,15 +89,52 @@ module.exports = function (grunt) {
});
});

grunt.registerTask('build', ['checkGitSubmodules', 'webpack:all']);
grunt.registerTask('build', ['checkGitSubmodules', 'webpack:all', 'build:browser']);

grunt.registerTask('build:node', ['checkGitSubmodules', 'webpack:node']);

grunt.registerTask('build:browser', ['checkGitSubmodules', 'webpack:browser']);

grunt.registerTask('check-closure-compiler', ['build', 'closureCompiler:ably.js']);
grunt.registerTask('all', ['build', 'requirejs']);

grunt.registerTask('build:browser', function () {
var done = this.async();

var baseConfig = {
entryPoints: ['src/platform/web/index.ts'],
outfile: 'build/ably.js',
bundle: true,
sourcemap: true,
format: 'umd',
banner: { js: '/*' + banner + '*/' },
plugins: [umdWrapper.default()],
target: 'es6',
};

grunt.registerTask('all', ['build', 'check-closure-compiler', 'requirejs']);
Promise.all([
esbuild.build(baseConfig),
esbuild.build({
...baseConfig,
outfile: 'build/ably.min.js',
minify: true,
}),
esbuild.build({
...baseConfig,
entryPoints: ['src/platform/web-noencryption/index.ts'],
outfile: 'build/ably.noencryption.js',
}),

esbuild.build({
...baseConfig,
entryPoints: ['src/platform/web-noencryption/index.ts'],
outfile: 'build/ably.noencryption.min.js',
minify: true,
}),
]).then(() => {
console.log('esbuild succeeded');
done(true);
});
});

grunt.loadTasks('test/tasks');

Expand Down
Loading

0 comments on commit c508a39

Please sign in to comment.