Skip to content

Commit

Permalink
build: use esbuild for browser bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
owenpearson committed Jul 10, 2023
1 parent ed9be58 commit 4d22ee2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 43 deletions.
44 changes: 43 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
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');
Expand Down Expand Up @@ -86,14 +89,53 @@ 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('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',
};

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');

grunt.registerTask('test', ['test:node']);
Expand Down
42 changes: 0 additions & 42 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,21 +137,6 @@ const reactNativeConfig = {
},
};

const browserMinConfig = {
...browserConfig,
output: {
...baseConfig.output,
filename: 'ably.min.js',
},
optimization: {
minimize: true,
},
performance: {
hints: 'warning',
},
devtool: 'source-map',
};

const webworkerConfig = {
target: ['webworker', 'es5'],
...browserConfig,
Expand Down Expand Up @@ -181,36 +166,9 @@ const webworkerConfig = {
],
};

const noEncryptionConfig = {
...browserConfig,
entry: {
index: platformPath('web-noencryption'),
},
output: {
...baseConfig.output,
filename: 'ably.noencryption.js',
},
};

const noEncryptionMinConfig = {
...browserMinConfig,
entry: {
index: platformPath('web-noencryption'),
},
output: {
...baseConfig.output,
filename: 'ably.noencryption.min.js',
},
devtool: 'source-map',
};

module.exports = {
node: nodeConfig,
browser: browserConfig,
browserMin: browserMinConfig,
webworker: webworkerConfig,
nativeScript: nativeScriptConfig,
reactNative: reactNativeConfig,
noEncryption: noEncryptionConfig,
noEncryptionMin: noEncryptionMinConfig,
};

0 comments on commit 4d22ee2

Please sign in to comment.