Class AddBundleOptions.Builder

    • Constructor Detail

      • Builder

        public Builder()
    • Method Detail

      • banner

        @Stability(Experimental)
        public AddBundleOptions.Builder banner​(String banner)
        Parameters:
        banner - Use this to insert an arbitrary string at the beginning of generated JavaScript files. This is similar to footer which inserts at the end instead of the beginning.

        This is commonly used to insert comments:

        Returns:
        this
      • charset

        @Stability(Experimental)
        public AddBundleOptions.Builder charset​(Charset charset)
        Parameters:
        charset - The charset to use for esbuild's output. By default esbuild's output is ASCII-only. Any non-ASCII characters are escaped using backslash escape sequences. Using escape sequences makes the generated output slightly bigger, and also makes it harder to read. If you would like for esbuild to print the original characters without using escape sequences, use Charset.UTF8.
        Returns:
        this
      • define

        @Stability(Experimental)
        public AddBundleOptions.Builder define​(Map<String,​String> define)
        Parameters:
        define - Replace global identifiers with constant expressions. For example, { 'process.env.DEBUG': 'true' }.

        Another example, { 'process.env.API_KEY': JSON.stringify('xxx-xxxx-xxx') }.

        Returns:
        this
      • esbuildArgs

        @Stability(Experimental)
        public AddBundleOptions.Builder esbuildArgs​(Map<String,​? extends Object> esbuildArgs)
        Parameters:
        esbuildArgs - Build arguments to pass into esbuild. For example, to add the --log-limit flag:

                            project.bundler.addBundle("./src/hello.ts", {
                              platform: "node",
                              target: "node18",
                              sourcemap: true,
                              format: "esm",
                              esbuildArgs: {
                                "--log-limit": "0",
                              },
                            });
                            
        Returns:
        this
      • footer

        @Stability(Experimental)
        public AddBundleOptions.Builder footer​(String footer)
        Parameters:
        footer - Use this to insert an arbitrary string at the end of generated JavaScript files. This is similar to banner which inserts at the beginning instead of the end.

        This is commonly used to insert comments

        Returns:
        this
      • format

        @Stability(Experimental)
        public AddBundleOptions.Builder format​(String format)
        Parameters:
        format - Output format for the generated JavaScript files. There are currently three possible values that can be configured: "iife", "cjs", and "esm".

        If not set (undefined), esbuild picks an output format for you based on platform:

        • "cjs" if platform is "node"
        • "iife" if platform is "browser"
        • "esm" if platform is "neutral"

        Note: If making a bundle to run under node with ESM, set format to "esm" instead of setting platform to "neutral".

        Returns:
        this
      • keepNames

        @Stability(Experimental)
        public AddBundleOptions.Builder keepNames​(Boolean keepNames)
        Parameters:
        keepNames - Whether to preserve the original name values even in minified code. In JavaScript the name property on functions and classes defaults to a nearby identifier in the source code.

        However, minification renames symbols to reduce code size and bundling sometimes need to rename symbols to avoid collisions. That changes value of the name property for many of these cases. This is usually fine because the name property is normally only used for debugging. However, some frameworks rely on the name property for registration and binding purposes. If this is the case, you can enable this option to preserve the original name values even in minified code.

        Returns:
        this
      • loaders

        @Stability(Experimental)
        public AddBundleOptions.Builder loaders​(Map<String,​String> loaders)
        Parameters:
        loaders - Map of file extensions (without dot) and loaders to use for this file type. Loaders are appended to the esbuild command by --loader:.extension=loader
        Returns:
        this
      • metafile

        @Stability(Experimental)
        public AddBundleOptions.Builder metafile​(Boolean metafile)
        Parameters:
        metafile - This option tells esbuild to write out a JSON file relative to output directory with metadata about the build. The metadata in this JSON file follows this schema (specified using TypeScript syntax):

                         {
                           outputs: {
                             [path: string]: {
                               bytes: number
                               inputs: {
                                 [path: string]: { bytesInOutput: number }
                               }
                               imports: { path: string }[]
                               exports: string[]
                             }
                           }
                         }
                         

        This data can then be analyzed by other tools. For example, bundle buddy can consume esbuild's metadata format and generates a treemap visualization of the modules in your bundle and how much space each one takes up.

        Returns:
        this
      • externals

        @Stability(Experimental)
        public AddBundleOptions.Builder externals​(List<String> externals)
        Parameters:
        externals - You can mark a file or a package as external to exclude it from your build. Instead of being bundled, the import will be preserved (using require for the iife and cjs formats and using import for the esm format) and will be evaluated at run time instead.

        This has several uses. First of all, it can be used to trim unnecessary code from your bundle for a code path that you know will never be executed. For example, a package may contain code that only runs in node but you will only be using that package in the browser. It can also be used to import code in node at run time from a package that cannot be bundled. For example, the fsevents package contains a native extension, which esbuild doesn't support.

        Returns:
        this
      • watchTask

        @Stability(Experimental)
        public AddBundleOptions.Builder watchTask​(Boolean watchTask)
        Parameters:
        watchTask - In addition to the bundle:xyz task, creates bundle:xyz:watch task which will invoke the same esbuild command with the --watch flag. This can be used to continusouly watch for changes.
        Returns:
        this