bundlessdev
v1.0.12
Published
Build on Browser, Bundle less
Readme
Build more, bundle less.
Create react apps without bundling.
Bundless.js: A 36kb browser shim that resolves and transpiles React JSX code at runtime.
Try it out - Examples - Benchmarks
Usage
All type='text/jsx', /tsx, and /babel scripts will be transpiled onDomLoad when you place the following tag in your html page:
JSX & Typescript link: 52Kb | source-maps
<script src="./bundless.sucrase.min.js"></script>JSX Only link: 36Kb | no source-maps
<script src="./bundless.acorn.min.js"></script>- Add
to="preact"if you want your react code transpiled to preact. - Add
cache="false"if you want transformed import URLs to receive a cache-busting query string. - Tips on Toubleshooting
That's it!
Module prefetching
Use an inert JSON script when an app already knows which JS, JSX, or TS module URLs it will import soon:
<script type="application/json" data-bundless-prefetch>
["./components/App.jsx", "./routes/Dashboard.jsx?startup=1"]
</script>On DOMContentLoaded, Bundless parses all data-bundless-prefetch JSON lists, warns and skips malformed blocks or non-string entries, then concurrently fetches and transpiles each listed module without evaluating it. Later window.import() calls reuse the prepared code by normalized original URL, so equivalent URLs deduplicate while query strings and cache busters remain distinct. Failed preparations are evicted so retrying can prepare again.
window.Bundless.prefetch() remains available for script-driven prefetching. It accepts one URL or an iterable of URLs, fetches module source only, and shares the same source-fetch cache that window.import() uses when no prepared code is available. Failed prefetches and failed imports are evicted so retries fetch again.
Webpack migration
Bundless apps can move to Webpack without changing application modules that call window.import():
const BundlessWebpackPlugin = require("bundlessdev/webpack");
module.exports = {
entry: "./src/index.jsx",
module: {
rules: [
{
test: /\.[jt]sx?$/,
exclude: /node_modules/,
use: "babel-loader"
}
]
},
plugins: [new BundlessWebpackPlugin()]
};The plugin injects a small pre-loader for JavaScript, JSX, TypeScript, and TSX files. Literal window.import("./Widget.jsx") calls become native import("./Widget.jsx") expressions so Webpack owns module resolution and chunking. window.Bundless.prefetch("./Widget.jsx") and string-array prefetches become Webpack prefetch hints that return a resolved Promise; pass { prefetch: "noop" } to make prefetch calls pure no-ops instead.
Bundless does not transform JSX in Webpack. Keep React imports in your source and configure Babel, SWC, esbuild, or another JSX loader exactly as you normally would.
Use a normal Webpack entry and avoid the browser runtime bootstrap in the built app. Remove the Bundless <script src="...bundless.*.js"> tag, type="text/jsx"/type="text/babel" script tags, and data-bundless-prefetch JSON tags from your production HTML template, or keep using HtmlWebpackPlugin and let new BundlessWebpackPlugin() strip those tags from emitted HTML. Add data-webpack-ignore to a data-bundless-prefetch block if you need HtmlWebpackPlugin output to preserve it; Webpack does not inspect the list contents. The plugin also aliases Bundless runtime package entry points to false by default so accidental runtime imports are not bundled. For manual rule wiring, the loader is exported as bundlessdev/webpack/loader.
Source maps
Acorn and Meriyah intentionally split their runtime source-map behavior by build variant. The .dev.js variants include runtime inline source maps for debugging. The default/minified variants, such as bundless.acorn.min.js and bundless.meriyah.min.js, and the explicit .prod.js variants omit runtime source maps to avoid production size and runtime overhead.
This policy is specific to the Acorn and Meriyah runtime transpiler paths. Babel and Sucrase keep their existing transpiler-specific source-map behavior rather than following the Acorn/Meriyah dev/prod matrix.
How it works
- Modules resolve using
<script type="importmap">. - Static imports are rewritten to the custom
window.import()loader. data-bundless-prefetchJSON tags can prepare modules without evaluating them, whilewindow.Bundless.prefetch()warms the source-fetch cache only.window.import()reuses any prepared code when present, otherwise reuses fetched source, transpiles it, then imports the transpiled blob.- Repeated or concurrent imports of the same normalized original module URL share the same pending promise and resolved module.
- Failed preparations and imports are removed from their caches so the next call can retry, and cache-busting query strings remain part of the cache key.
Publication
- Git tags now drive the release flow through GitHub Actions.
- Release builds are expected to be created locally before you tag and push a release.
- Release bundles are attached to GitHub Releases and can be fetched from the GitHub-backed jsDelivr CDN, for example
https://cdn.jsdelivr.net/gh/karpatic/[email protected]/dist/bundless.acorn.min.js. - GitHub Releases are live through
v1.0.10, and the GitHub-backed jsDelivr route is the current verified CDN path. - The npm package
bundlessdevis published to npmjs, and the same release flow can also publish a GitHub Packages variant as@karpatic/bundlessdev. - Run
npm test, run the local release build, bumppackage.jsonandpackage-lock.json, and then push a version tag likev1.0.10; GitHub Actions will use the checked-indistfiles to create the GitHub Release, publishbundlessdevto npm through trusted publishing via OIDC, and publish@karpatic/bundlessdevto GitHub Packages withGITHUB_TOKEN. - The release workflow now runs on version tags instead of every
mainpush so release history stays focused on real versioned releases.
