A Bublé configuration that transpiles modern JavaScript for Rhino, the Java-based JavaScript engine made by Mozilla.
Bublé is a JavaScript transpiler that transpiles modern JavaScript for legacy JavaScript runtimes that only support ES5. Mozilla Rhino is one such system.
This package provides a configuration (i.e. preset) for Bublé that can be reused across JavaScript projects targeting Rhino. It selectively enables transpilation for ES2015+ features unsupported by Rhino, while allowing supported features to be emitted as-is.
buble-config-rhino exports a single function. This function returns a
configuration object that can be passed to buble.transform()
, which then
transpiles modern ECMAScript to a subset of ES5+ that Rhino supports:
const buble = require("buble");
const createPreset = require("buble-config-rhino");
// Note: buble-config-rhino also provides native ESM exports
// import { createPreset } from "buble-config-rhino";
const output = buble.transform(code, createPreset());
If there is a feature that you want to turn on or off, you can pass an options
object to createPreset()
that will override the defaults:
const output = buble.transform(
code,
createPreset({
transforms: {
arrow: true,
dangerousTaggedTemplateString: false,
},
})
);
createPreset()
accepts the same options object as buble.transform()
.
Use @rollup/plugin-buble with this config:
// rollup.config.js
import buble from "@rollup/plugin-buble";
import createPreset from "buble-config-rhino";
export default {
// ...
plugins: [buble(createPreset())],
};
Use buble-loader with this config:
// webpack.config.js
const path = require("path");
const createPreset = require("buble-config-rhino");
module.exports = {
// ...
module: {
rules: [
{
test: /\.js$/,
loader: "buble-loader",
include: path.join(__dirname, "src"),
options: createPreset(),
},
],
},
};
See index.ts
for a list of enabled/disabled transforms.
Note that, unlike Babel, Bublé does not add polyfills. You must add them manually.
See also: List of ES2015+ features supported by Rhino (may be outdated)