Skip to content

Commit a59d519

Browse files
authored
Browser Bundle Improvements (#200)
* bump `ed25519` and `secp256k1` libs * 0.0.18 * import specific `lodash` method to reduce bundle size * output bundle metadata * improve browser bundle * include safari and firefox as targets * run headless browser tests in safari and firefox * use non-abandoned polyfill lib * add cjs dist and include in * patch security vuln * include `package.json` in `dist/cjs` to override `type: module` in parent `package.json` * add react-native directive to package.json
1 parent 58656ed commit a59d519

File tree

10 files changed

+2245
-148
lines changed

10 files changed

+2245
-148
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# bundle metadata
2+
bundle-metadata.json
3+
14
# js deps
25
node_modules
36
# bundler output location

build/create-browser-bundle.cjs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
const browserConfig = require('./esbuild-browser-config.cjs');
2+
const fs = require('fs');
23

34
require('esbuild').build({
45
...browserConfig,
5-
outfile: 'dist/bundles/browser.js',
6+
metafile : true,
7+
outfile : 'dist/bundles/browser.js',
8+
}).then(result => {
9+
const serializedMetafile = JSON.stringify(result.metafile, null, 4);
10+
fs.writeFileSync(`${__dirname}/../bundle-metadata.json`, serializedMetafile, { encoding: 'utf8' });
611
});

build/esbuild-browser-config.cjs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
const { NodeGlobalsPolyfillPlugin } = require('@esbuild-plugins/node-globals-polyfill');
1+
const polyfillProviderPlugin = require('node-stdlib-browser/helpers/esbuild/plugin');
2+
const stdLibBrowser = require('node-stdlib-browser');
23

4+
/** @type {import('esbuild').BuildOptions} */
35
module.exports = {
46
entryPoints : ['./src/index.ts'],
57
bundle : true,
68
format : 'esm',
79
sourcemap : true,
10+
minify : true,
811
platform : 'browser',
9-
target : ['chrome101'],
10-
plugins : [NodeGlobalsPolyfillPlugin()],
12+
target : ['chrome101', 'firefox108', 'safari16'],
13+
inject : [require.resolve('node-stdlib-browser/helpers/esbuild/shim')],
14+
plugins : [polyfillProviderPlugin(stdLibBrowser)],
1115
define : {
1216
'global': 'globalThis'
1317
}

build/publish-unstable.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ npm version $new_unstable_version --no-git-tag-version
1919
npm publish --tag unstable --no-git-tag-version
2020

2121
# Reset changes to the package.json
22-
git checkout -- package.json
22+
git checkout -- package.json
23+
git checkout -- package-lock.json

karma.conf.cjs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
// Karma is what we're using to run our tests in browser environments
22
// Karma does not support .mjs
33

4+
// playwright acts as a safari executable on windows and mac
5+
const playwright = require('playwright');
46
const esbuildBrowserConfig = require('./build/esbuild-browser-config.cjs');
57

8+
// set playwright as run-target for webkit tests
9+
process.env.WEBKIT_HEADLESS_BIN = playwright.webkit.executablePath();
10+
611
module.exports = function(config) {
712
config.set({
813
plugins: [
914
require('karma-chrome-launcher'),
15+
require('karma-firefox-launcher'),
16+
require('karma-webkit-launcher'),
1017
require('karma-esbuild'),
1118
require('karma-mocha'),
1219
require('karma-mocha-reporter')
@@ -47,9 +54,11 @@ module.exports = function(config) {
4754
// config.LOG_INFO || config.LOG_DEBUG
4855
logLevel: config.LOG_INFO,
4956

57+
concurrency: 1,
58+
5059
// start these browsers
5160
// available browser launchers: https://www.npmjs.com/search?q=keywords:karma-launcher
52-
browsers: ['ChromeHeadless'],
61+
browsers: ['ChromeHeadless', 'FirefoxHeadless', 'WebkitHeadless'],
5362

5463
// Continuous Integration mode
5564
// if true, Karma captures browsers, runs the tests and exits

0 commit comments

Comments
 (0)