KC's Workspace
    Preparing search index...

    Construct a type with the properties of T except for those in type K.

    interface TransformOptions {
        assumptions?: CompilerAssumptions;
        decorator?: DecoratorOptions;
        define?: Record<string, string>;
        dropLabels?: string[];
        helpers?: Helpers;
        inject?: Record<string, string | [string, string]>;
        jsx?: false | "react" | "react-jsx" | "preserve" | JsxOptions;
        plugins?: PluginsOptions;
        target?: string | string[];
        typescript?: TypeScriptOptions;
    }

    Hierarchy (View Summary)

    • Omit<
          TransformOptions,
          "sourceType"
          | "lang"
          | "cwd"
          | "sourcemap"
          | "define"
          | "inject"
          | "jsx",
      >
      • TransformOptions
    Index

    Properties

    assumptions?: CompilerAssumptions

    Set assumptions in order to produce smaller output.

    decorator?: DecoratorOptions

    Decorator plugin

    define?: Record<string, string>

    Replace global variables or property accessors with the provided values.

    Examples

    • Replace the global variable IS_PROD with true
    export default defineConfig({ transform: { define: { IS_PROD: 'true' } } })
    

    Result:

    // Input
    if (IS_PROD) {
    console.log('Production mode')
    }

    // After bundling
    if (true) {
    console.log('Production mode')
    }
    • Replace the property accessor process.env.NODE_ENV with 'production'
    export default defineConfig({ transform: { define: { 'process.env.NODE_ENV': "'production'" } } })
    

    Result:

    // Input
    if (process.env.NODE_ENV === 'production') {
    console.log('Production mode')
    }

    // After bundling
    if ('production' === 'production') {
    console.log('Production mode')
    }
    dropLabels?: string[]

    Remove labeled statements with these label names.

    Labeled statements are JavaScript statements prefixed with a label identifier. This option allows you to strip specific labeled statements from the output, which is useful for removing debug-only code in production builds.

    export default defineConfig({ transform: { dropLabels: ['DEBUG', 'DEV'] } })
    

    Result:

    // Input
    DEBUG: console.log('Debug info');
    DEV: {
    console.log('Development mode');
    }
    console.log('Production code');

    // After bundling
    console.log('Production code');
    helpers?: Helpers

    Behaviour for runtime helpers.

    inject?: Record<string, string | [string, string]>

    Inject import statements on demand.

    The API is aligned with @rollup/plugin-inject.

    {
    // import { Promise } from 'es6-promise'
    Promise: ['es6-promise', 'Promise'],

    // import { Promise as P } from 'es6-promise'
    P: ['es6-promise', 'Promise'],

    // import $ from 'jquery'
    $: 'jquery',

    // import * as fs from 'node:fs'
    fs: ['node:fs', '*'],

    // Inject shims for property access pattern
    'Object.assign': path.resolve( 'src/helpers/object-assign.js' ),
    }
    jsx?: false | "react" | "react-jsx" | "preserve" | JsxOptions
    plugins?: PluginsOptions

    Third-party plugins to use.

    target?: string | string[]

    Sets the target environment for the generated JavaScript.

    The lowest target is es2015.

    Example:

    • 'es2015'
    • ['es2020', 'chrome58', 'edge16', 'firefox57', 'node12', 'safari11']

    esnext (No transformation)

    typescript?: TypeScriptOptions

    Configure how TypeScript is transformed.