CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-babel--preset-env-standalone

Standalone build of babel-preset-env for use in non-Node.js environments.

Pending
Overview
Eval results
Files

@babel/preset-env-standalone

@babel/preset-env-standalone is a standalone build of @babel/preset-env designed for use in non-Node.js environments such as browsers and web workers. It registers the babel-preset-env preset with @babel/standalone and provides additional Babel plugins that extend the standard @babel/standalone distribution with modern JavaScript syntax and proposal support.

Package Information

  • Package Name: @babel/preset-env-standalone
  • Package Type: npm
  • Language: JavaScript (ES6 modules, built for browsers)
  • Installation: npm install @babel/preset-env-standalone

Core Imports

Browser environments (after including @babel/standalone):

<script src="node_modules/@babel/standalone/babel.min.js"></script>
<script src="node_modules/@babel/preset-env-standalone/babel-preset-env.min.js"></script>

Or using a module bundler:

import "@babel/preset-env-standalone";
import { version } from "@babel/preset-env-standalone";

CommonJS (Node.js environments):

require("@babel/preset-env-standalone");
const { version } = require("@babel/preset-env-standalone");

Basic Usage

// After including the standalone build, the "env" preset is available
const result = Babel.transform(code, {
  presets: ["env"]
});

// With target configuration
const result = Babel.transform(code, {
  presets: [
    ["env", {
      targets: {
        browsers: ["last 2 versions", "> 1%"]
      }
    }]
  ]
});

// Access version information
console.log(`Using @babel/preset-env-standalone version ${version}`);

Architecture

@babel/preset-env-standalone consists of three main components:

  • Main Module: Registers the "env" preset with @babel/standalone and exports version information
  • Available Plugins Module: Extends @babel/standalone with additional modern JavaScript plugins not included in the base distribution
  • Version Export: Provides runtime access to the package version

Capabilities

Preset Registration

Registers the "env" preset with @babel/standalone, enabling browser-based transpilation with @babel/preset-env functionality.

// Side effect: Registers "env" preset with @babel/standalone
// No direct API - registration occurs on module import

Usage Example:

// The preset becomes available after import/script inclusion
const transformed = Babel.transform(`
  const fn = (a = 1, ...rest) => ({ a, rest });
  const obj = { [key]: value };
`, {
  presets: ["env"]
});

Version Information

Provides access to the package version at runtime.

/**
 * The version of the @babel/preset-env-standalone package
 */
export const version: string;

Usage Example:

import { version } from "@babel/preset-env-standalone";
console.log(`@babel/preset-env-standalone version: ${version}`);

Additional Plugin Registration

Automatically registers modern JavaScript plugins that are not included in the standard @babel/standalone distribution.

// Side effect: Registers additional plugins with @babel/standalone
// The following plugins are made available:
// - proposal-dynamic-import
// - proposal-json-strings  
// - proposal-nullish-coalescing-operator
// - proposal-optional-chaining
// - syntax-json-strings
// - syntax-nullish-coalescing-operator
// - syntax-optional-chaining
// - syntax-top-level-await
// - transform-named-capturing-groups-regex
// - transform-new-target

Usage Example:

// These plugins become available for use in preset-env after import
const code = `
  const obj = data?.property ?? "default";
  const regex = /(?<year>\\d{4})-(?<month>\\d{2})/;
`;

const result = Babel.transform(code, {
  presets: [["env", { 
    targets: { browsers: ["last 2 versions"] }
  }]]
});

Available Plugins Export

Re-exports the enhanced available plugins object from @babel/standalone after plugin registration.

/**
 * Enhanced available plugins object from @babel/standalone
 * Contains all standard plugins plus additional modern JavaScript plugins
 */
export default availablePlugins: { [pluginName: string]: Function };

Types

/**
 * Version string for the package
 */
type Version = string;

/**
 * Available plugins registry - maps plugin names to plugin functions
 */
type AvailablePlugins = {
  [pluginName: string]: Function;
};

Browser Compatibility

This package is specifically designed for browser environments and requires:

  • @babel/standalone to be loaded first
  • ES5+ browser support (IE9+)
  • Module system support (script tags or bundler)

The package provides polyfill and transpilation support for modern JavaScript features based on the configured browser targets in the "env" preset options.

Install with Tessl CLI

npx tessl i tessl/npm-babel--preset-env-standalone
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@babel/preset-env-standalone@7.8.x
Publish Source
CLI
Badge
tessl/npm-babel--preset-env-standalone badge