Class AddBundleOptions.Builder
- java.lang.Object
-
- io.github.cdklabs.projen.javascript.AddBundleOptions.Builder
-
- All Implemented Interfaces:
software.amazon.jsii.Builder<AddBundleOptions>
- Enclosing interface:
- AddBundleOptions
@Stability(Experimental) public static final class AddBundleOptions.Builder extends Object implements software.amazon.jsii.Builder<AddBundleOptions>
A builder forAddBundleOptions
-
-
Constructor Summary
Constructors Constructor Description Builder()
-
Method Summary
-
-
-
Method Detail
-
platform
@Stability(Experimental) public AddBundleOptions.Builder platform(String platform)
Sets the value ofAddBundleOptions.getPlatform()- Parameters:
platform- esbuild platform. This parameter is required.- Returns:
this
-
target
@Stability(Experimental) public AddBundleOptions.Builder target(String target)
Sets the value ofAddBundleOptions.getTarget()- Parameters:
target- esbuild target. This parameter is required.- Returns:
this
-
banner
@Stability(Experimental) public AddBundleOptions.Builder banner(String banner)
Sets the value ofAddBundleOptions.getBanner()- 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)
Sets the value ofAddBundleOptions.getCharset()- 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, useCharset.UTF8.- Returns:
this
-
define
@Stability(Experimental) public AddBundleOptions.Builder define(Map<String,String> define)
Sets the value ofAddBundleOptions.getDefine()- 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)
Sets the value ofAddBundleOptions.getEsbuildArgs()- 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
-
executable
@Stability(Experimental) public AddBundleOptions.Builder executable(Boolean executable)
Sets the value ofAddBundleOptions.getExecutable()- Parameters:
executable- Mark the output file as executable.- Returns:
this
-
footer
@Stability(Experimental) public AddBundleOptions.Builder footer(String footer)
Sets the value ofAddBundleOptions.getFooter()- 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)
Sets the value ofAddBundleOptions.getFormat()- 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 onplatform:"cjs"ifplatformis"node""iife"ifplatformis"browser""esm"ifplatformis"neutral"
Note: If making a bundle to run under node with ESM, set
formatto"esm"instead of settingplatformto"neutral".- Returns:
this
-
inject
@Stability(Experimental) public AddBundleOptions.Builder inject(List<String> inject)
Sets the value ofAddBundleOptions.getInject()- Parameters:
inject- This option allows you to automatically replace a global variable with an import from another file.- Returns:
this
-
keepNames
@Stability(Experimental) public AddBundleOptions.Builder keepNames(Boolean keepNames)
Sets the value ofAddBundleOptions.getKeepNames()- Parameters:
keepNames- Whether to preserve the originalnamevalues even in minified code. In JavaScript thenameproperty 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
nameproperty for many of these cases. This is usually fine because thenameproperty is normally only used for debugging. However, some frameworks rely on thenameproperty for registration and binding purposes. If this is the case, you can enable this option to preserve the originalnamevalues even in minified code.- Returns:
this
-
loaders
@Stability(Experimental) public AddBundleOptions.Builder loaders(Map<String,String> loaders)
Sets the value ofAddBundleOptions.getLoaders()- 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
-
logLevel
@Stability(Experimental) public AddBundleOptions.Builder logLevel(BundleLogLevel logLevel)
Sets the value ofAddBundleOptions.getLogLevel()- Parameters:
logLevel- Log level for esbuild. This is also propagated to the package manager and applies to its specific install command.- Returns:
this
-
mainFields
@Stability(Experimental) public AddBundleOptions.Builder mainFields(List<String> mainFields)
Sets the value ofAddBundleOptions.getMainFields()- Parameters:
mainFields- How to determine the entry point for modules. Try ['module', 'main'] to default to ES module versions.- Returns:
this
-
metafile
@Stability(Experimental) public AddBundleOptions.Builder metafile(Boolean metafile)
Sets the value ofAddBundleOptions.getMetafile()- 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
-
minify
@Stability(Experimental) public AddBundleOptions.Builder minify(Boolean minify)
Sets the value ofAddBundleOptions.getMinify()- Parameters:
minify- Whether to minify files when bundling.- Returns:
this
-
outfile
@Stability(Experimental) public AddBundleOptions.Builder outfile(String outfile)
Sets the value ofAddBundleOptions.getOutfile()- Parameters:
outfile- Bundler output path relative to the asset's output directory.- Returns:
this
-
sourceMapMode
@Stability(Experimental) public AddBundleOptions.Builder sourceMapMode(SourceMapMode sourceMapMode)
Sets the value ofAddBundleOptions.getSourceMapMode()- Parameters:
sourceMapMode- Source map mode to be used when bundling.- Returns:
this
-
sourcesContent
@Stability(Experimental) public AddBundleOptions.Builder sourcesContent(Boolean sourcesContent)
Sets the value ofAddBundleOptions.getSourcesContent()- Parameters:
sourcesContent- Whether to include original source code in source maps when bundling.- Returns:
this
-
tsconfigPath
@Stability(Experimental) public AddBundleOptions.Builder tsconfigPath(String tsconfigPath)
Sets the value ofAddBundleOptions.getTsconfigPath()- Parameters:
tsconfigPath- The path of the tsconfig.json file to use for bundling.- Returns:
this
-
externals
@Stability(Experimental) public AddBundleOptions.Builder externals(List<String> externals)
Sets the value ofBundlingOptions.getExternals()- 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
-
sourcemap
@Stability(Experimental) public AddBundleOptions.Builder sourcemap(Boolean sourcemap)
Sets the value ofBundlingOptions.getSourcemap()- Parameters:
sourcemap- Include a source map in the bundle.- Returns:
this
-
watchTask
@Stability(Experimental) public AddBundleOptions.Builder watchTask(Boolean watchTask)
Sets the value ofBundlingOptions.getWatchTask()- Parameters:
watchTask- In addition to thebundle:xyztask, createsbundle:xyz:watchtask which will invoke the same esbuild command with the--watchflag. This can be used to continusouly watch for changes.- Returns:
this
-
build
@Stability(Experimental) public AddBundleOptions build()
Builds the configured instance.- Specified by:
buildin interfacesoftware.amazon.jsii.Builder<AddBundleOptions>- Returns:
- a new instance of
AddBundleOptions - Throws:
NullPointerException- if any required attribute was not provided
-
-