diff --git a/Gruntfile.js b/Gruntfile.js index bf159a0ee9..ca1f636f9a 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -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'); @@ -86,7 +89,7 @@ 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']); @@ -94,6 +97,45 @@ module.exports = function (grunt) { 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']); diff --git a/webpack.config.js b/webpack.config.js index 2c0c981ca7..c569d64272 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -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, @@ -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, };