bundle-require

  • Version 5.0.0
  • Published
  • 26 kB
  • 1 dependency
  • MIT license

Install

npm i bundle-require
yarn add bundle-require
pnpm add bundle-require

Overview

bundle and require a file

Index

Variables

variable dynamicImport

const dynamicImport: RequireFunction;
  • Dynamically import files.

    As a temporary workaround for Jest's lack of stable ESM support, we fallback to require if we're in a Jest environment. See https://github.com/vitejs/vite/pull/5197#issuecomment-938054077

    Parameter file

    File path to import.

variable JS_EXT_RE

const JS_EXT_RE: RegExp;

    Functions

    function bundleRequire

    bundleRequire: <T = any>(
    options: Options
    ) => Promise<{ mod: T; dependencies: string[] }>;

      function externalPlugin

      externalPlugin: ({
      external,
      notExternal,
      externalNodeModules,
      }?: {
      external?: (string | RegExp)[] | undefined;
      notExternal?: (string | RegExp)[] | undefined;
      externalNodeModules?: boolean | undefined;
      }) => Plugin;
      • An esbuild plugin to mark node_modules as external

      function injectFileScopePlugin

      injectFileScopePlugin: () => Plugin;

        function match

        match: (id: string, patterns?: (string | RegExp)[]) => boolean;

          function tsconfigPathsToRegExp

          tsconfigPathsToRegExp: (paths: Record<string, any>) => RegExp[];

            Interfaces

            interface Options

            interface Options {}

              property cwd

              cwd?: string;

                property esbuildOptions

                esbuildOptions?: BuildOptions & {
                watch?:
                | boolean
                | {
                onRebuild?: RebuildCallback;
                };
                };
                • esbuild options

                  Deprecated

                  esbuildOptions.watch is deprecated, use onRebuild instead

                property external

                external?: (string | RegExp)[];
                • External packages

                property externalNodeModules

                externalNodeModules?: boolean;
                • Automatically mark node_modules as external true - false when filepath is in node_modules

                property filepath

                filepath: string;
                • The filepath to bundle and require

                property format

                format?: 'cjs' | 'esm';
                • Provide bundle format explicitly to skip the default format inference

                property getOutputFile

                getOutputFile?: GetOutputFile;
                • Get the path to the output file By default we simply replace the extension with .bundled_{randomId}.js

                property notExternal

                notExternal?: (string | RegExp)[];
                • Not external packages

                property onRebuild

                onRebuild?: (ctx: {
                err?: Pick<BuildFailure, 'errors' | 'warnings'>;
                mod?: any;
                dependencies?: string[];
                }) => void;
                • Enable watching and call the callback after each rebuild

                property preserveTemporaryFile

                preserveTemporaryFile?: boolean;
                • Preserve compiled temporary file for debugging Default to process.env.BUNDLE_REQUIRE_PRESERVE

                property require

                require?: RequireFunction;
                • The require function that is used to load the output file Default to the global require function This function can be asynchronous, i.e. returns a Promise

                property tsconfig

                tsconfig?: string | TsconfigRaw | false;
                • A custom tsconfig path to read paths option

                  Set to false to disable tsconfig Or provide a TsconfigRaw object

                Type Aliases

                type GetOutputFile

                type GetOutputFile = (filepath: string, format: 'esm' | 'cjs') => string;

                  type RebuildCallback

                  type RebuildCallback = (
                  error: Pick<BuildFailure, 'errors' | 'warnings'> | null,
                  result: BuildResult | null
                  ) => void;

                    type RequireFunction

                    type RequireFunction = (
                    outfile: string,
                    ctx: {
                    format: 'cjs' | 'esm';
                    }
                    ) => any;

                      Package Files (1)

                      Dependencies (1)

                      Dev Dependencies (7)

                      Peer Dependencies (1)

                      Badge

                      To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                      You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/bundle-require.

                      • Markdown
                        [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/bundle-require)
                      • HTML
                        <a href="https://www.jsdocs.io/package/bundle-require"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>