onBeforeParse

Bun

Symbol

PluginBuilder.onBeforeParse

onBeforeParse(constraints: PluginConstraints, callback: { external: unknown; napiModule: unknown; symbol: string }): this

Referenced types

interface PluginConstraints

  • filter: RegExp

    Only apply the plugin when the import specifier matches this regular expression

    // Only apply the plugin when the import specifier matches the regex
    Bun.plugin({
     setup(builder) {
        builder.onLoad({ filter: /node_modules/underscore/ }, (args) => {
         return { contents: "throw new Error('Please use lodash instead of underscore.')" };
        });
     }
    })
    
  • namespace?: string

    Only apply the plugin when the import specifier has a namespace matching this string

    Namespaces are prefixes in import specifiers. For example, "bun:ffi" has the namespace "bun".

    The default namespace is "file" and it can be omitted from import specifiers.