Skip to content
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

Browser Bundle Improvements #200

Merged
merged 9 commits into from
Jan 26, 2023
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# bundle metadata
bundle-metadata.json

# js deps
node_modules
# bundler output location
Expand Down
7 changes: 6 additions & 1 deletion build/create-browser-bundle.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
const browserConfig = require('./esbuild-browser-config.cjs');
const fs = require('fs');

require('esbuild').build({
...browserConfig,
outfile: 'dist/bundles/browser.js',
metafile : true,
outfile : 'dist/bundles/browser.js',
}).then(result => {
const serializedMetafile = JSON.stringify(result.metafile, null, 4);
fs.writeFileSync(`${__dirname}/../bundle-metadata.json`, serializedMetafile, { encoding: 'utf8' });
});
10 changes: 7 additions & 3 deletions build/esbuild-browser-config.cjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
const { NodeGlobalsPolyfillPlugin } = require('@esbuild-plugins/node-globals-polyfill');
const polyfillProviderPlugin = require('node-stdlib-browser/helpers/esbuild/plugin');
const stdLibBrowser = require('node-stdlib-browser');

/** @type {import('esbuild').BuildOptions} */
module.exports = {
entryPoints : ['./src/index.ts'],
bundle : true,
format : 'esm',
sourcemap : true,
minify : true,
platform : 'browser',
target : ['chrome101'],
plugins : [NodeGlobalsPolyfillPlugin()],
target : ['chrome101', 'firefox108', 'safari16'],
inject : [require.resolve('node-stdlib-browser/helpers/esbuild/shim')],
plugins : [polyfillProviderPlugin(stdLibBrowser)],
define : {
'global': 'globalThis'
}
Expand Down
3 changes: 2 additions & 1 deletion build/publish-unstable.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ npm version $new_unstable_version --no-git-tag-version
npm publish --tag unstable --no-git-tag-version

# Reset changes to the package.json
git checkout -- package.json
git checkout -- package.json
git checkout -- package-lock.json
11 changes: 10 additions & 1 deletion karma.conf.cjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
// Karma is what we're using to run our tests in browser environments
// Karma does not support .mjs

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

// set playwright as run-target for webkit tests
process.env.WEBKIT_HEADLESS_BIN = playwright.webkit.executablePath();

module.exports = function(config) {
config.set({
plugins: [
require('karma-chrome-launcher'),
require('karma-firefox-launcher'),
require('karma-webkit-launcher'),
require('karma-esbuild'),
require('karma-mocha'),
require('karma-mocha-reporter')
Expand Down Expand Up @@ -47,9 +54,11 @@ module.exports = function(config) {
// config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,

concurrency: 1,

// start these browsers
// available browser launchers: https://www.npmjs.com/search?q=keywords:karma-launcher
browsers: ['ChromeHeadless'],
browsers: ['ChromeHeadless', 'FirefoxHeadless', 'WebkitHeadless'],

// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
Expand Down
Loading