Class BundlingOptions.Builder
- All Implemented Interfaces:
software.amazon.jsii.Builder<BundlingOptions>
- Enclosing interface:
BundlingOptions
BundlingOptions
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionSets the value ofBundlingOptions.getAssetHash()
Sets the value ofBundlingOptions.getBanner()
build()
Builds the configured instance.Sets the value ofBundlingOptions.getBuildArgs()
bundleAwsSdk
(Boolean bundleAwsSdk) Sets the value ofinvalid @link
BundlingOptions#getBundleAwsSdk
bundlingFileAccess
(BundlingFileAccess bundlingFileAccess) Sets the value ofBundlingOptions.getBundlingFileAccess()
Sets the value ofBundlingOptions.getCharset()
Sets the value ofDockerRunOptions.getCommand()
commandHooks
(ICommandHooks commandHooks) Sets the value ofBundlingOptions.getCommandHooks()
Sets the value ofBundlingOptions.getDefine()
dockerImage
(DockerImage dockerImage) Sets the value ofBundlingOptions.getDockerImage()
entrypoint
(List<String> entrypoint) Sets the value ofDockerRunOptions.getEntrypoint()
environment
(Map<String, String> environment) Sets the value ofDockerRunOptions.getEnvironment()
esbuildArgs
(Map<String, ? extends Object> esbuildArgs) Sets the value ofBundlingOptions.getEsbuildArgs()
esbuildVersion
(String esbuildVersion) Sets the value ofBundlingOptions.getEsbuildVersion()
externalModules
(List<String> externalModules) Sets the value ofBundlingOptions.getExternalModules()
Sets the value ofBundlingOptions.getFooter()
forceDockerBundling
(Boolean forceDockerBundling) Sets the value ofBundlingOptions.getForceDockerBundling()
format
(OutputFormat format) Sets the value ofBundlingOptions.getFormat()
Sets the value ofBundlingOptions.getInject()
Sets the value ofBundlingOptions.getKeepNames()
Sets the value ofBundlingOptions.getLoader()
Sets the value ofBundlingOptions.getLogLevel()
mainFields
(List<String> mainFields) Sets the value ofBundlingOptions.getMainFields()
Sets the value ofBundlingOptions.getMetafile()
Sets the value ofBundlingOptions.getMinify()
Sets the value ofDockerRunOptions.getNetwork()
nodeModules
(List<String> nodeModules) Sets the value ofBundlingOptions.getNodeModules()
Sets the value ofDockerRunOptions.getPlatform()
preCompilation
(Boolean preCompilation) Sets the value ofBundlingOptions.getPreCompilation()
securityOpt
(String securityOpt) Sets the value ofDockerRunOptions.getSecurityOpt()
Sets the value ofBundlingOptions.getSourceMap()
sourceMapMode
(SourceMapMode sourceMapMode) Sets the value ofBundlingOptions.getSourceMapMode()
sourcesContent
(Boolean sourcesContent) Sets the value ofBundlingOptions.getSourcesContent()
Sets the value ofBundlingOptions.getTarget()
Sets the value ofBundlingOptions.getTsconfig()
Sets the value ofDockerRunOptions.getUser()
volumes
(List<? extends DockerVolume> volumes) Sets the value ofDockerRunOptions.getVolumes()
volumesFrom
(List<String> volumesFrom) Sets the value ofDockerRunOptions.getVolumesFrom()
workingDirectory
(String workingDirectory) Sets the value ofDockerRunOptions.getWorkingDirectory()
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
assetHash
Sets the value ofBundlingOptions.getAssetHash()
- Parameters:
assetHash
- Specify a custom hash for this asset. For consistency, this custom hash will be SHA256 hashed and encoded as hex. The resulting hash will be the asset hash.NOTE: the hash is used in order to identify a specific revision of the asset, and used for optimizing and caching deployment activities related to this asset such as packaging, uploading to Amazon S3, etc. If you chose to customize the hash, you will need to make sure it is updated every time the asset changes, or otherwise it is possible that some deployments will not be invalidated.
- Returns:
this
-
banner
Sets the value ofBundlingOptions.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
-
buildArgs
Sets the value ofBundlingOptions.getBuildArgs()
- Parameters:
buildArgs
- Build arguments to pass when building the bundling image.- Returns:
this
-
bundleAwsSdk
Sets the value ofinvalid @link
BundlingOptions#getBundleAwsSdk
- Parameters:
bundleAwsSdk
- Includes AWS SDK in the bundle asset.- Returns:
this
-
bundlingFileAccess
@Stability(Stable) public BundlingOptions.Builder bundlingFileAccess(BundlingFileAccess bundlingFileAccess) Sets the value ofBundlingOptions.getBundlingFileAccess()
- Parameters:
bundlingFileAccess
- Which option to use to copy the source files to the docker container and output files back.- Returns:
this
-
charset
Sets the value ofBundlingOptions.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
-
commandHooks
Sets the value ofBundlingOptions.getCommandHooks()
- Parameters:
commandHooks
- Command hooks.- Returns:
this
-
define
Sets the value ofBundlingOptions.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
-
dockerImage
Sets the value ofBundlingOptions.getDockerImage()
- Parameters:
dockerImage
- A custom bundling Docker image. This image should have esbuild installed globally. If you plan to usenodeModules
it should also havenpm
,yarn
orpnpm
depending on the lock file you're using.See https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-lambda-nodejs/lib/Dockerfile for the default image provided by aws-cdk-lib/aws-lambda-nodejs.
- Returns:
this
-
esbuildArgs
@Stability(Stable) public BundlingOptions.Builder esbuildArgs(Map<String, ? extends Object> esbuildArgs) Sets the value ofBundlingOptions.getEsbuildArgs()
- Parameters:
esbuildArgs
- Build arguments to pass into esbuild. For example, to add the --log-limit flag:new NodejsFunction(scope, id, { ... bundling: { esbuildArgs: { "--log-limit": "0", } } });
- Returns:
this
-
esbuildVersion
Sets the value ofBundlingOptions.getEsbuildVersion()
- Parameters:
esbuildVersion
- The version of esbuild to use when running in a Docker container.- Returns:
this
-
externalModules
Sets the value ofBundlingOptions.getExternalModules()
- Parameters:
externalModules
- A list of modules that should be considered as externals (already available in the runtime).- Returns:
this
-
forceDockerBundling
Sets the value ofBundlingOptions.getForceDockerBundling()
- Parameters:
forceDockerBundling
- Force bundling in a Docker container even if local bundling is possible. This is useful if your function relies on node modules that should be installed (nodeModules
) in a Lambda compatible environment.- Returns:
this
-
format
Sets the value ofBundlingOptions.getFormat()
- Parameters:
format
- Output format for the generated JavaScript files.- Returns:
this
-
inject
Sets the value ofBundlingOptions.getInject()
- Parameters:
inject
- This option allows you to automatically replace a global variable with an import from another file.- Returns:
this
-
keepNames
Sets the value ofBundlingOptions.getKeepNames()
- Parameters:
keepNames
- Whether to preserve the originalname
values even in minified code. In JavaScript thename
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 thename
property is normally only used for debugging. However, some frameworks rely on thename
property for registration and binding purposes. If this is the case, you can enable this option to preserve the originalname
values even in minified code.- Returns:
this
-
loader
Sets the value ofBundlingOptions.getLoader()
- Parameters:
loader
- Use loaders to change how a given input file is interpreted. Configuring a loader for a given file type lets you load that file type with animport
statement or arequire
call.For example,
{ '.png': 'dataurl' }
.- Returns:
this
-
logLevel
Sets the value ofBundlingOptions.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
Sets the value ofBundlingOptions.getMainFields()
- Parameters:
mainFields
- How to determine the entry point for modules. Try ['module', 'main'] to default to ES module versions.- Returns:
this
-
metafile
Sets the value ofBundlingOptions.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
Sets the value ofBundlingOptions.getMinify()
- Parameters:
minify
- Whether to minify files when bundling.- Returns:
this
-
nodeModules
Sets the value ofBundlingOptions.getNodeModules()
- Parameters:
nodeModules
- A list of modules that should be installed instead of bundled. Modules are installed in a Lambda compatible environment only when bundling runs in Docker.- Returns:
this
-
preCompilation
Sets the value ofBundlingOptions.getPreCompilation()
- Parameters:
preCompilation
- Run compilation using tsc before running file through bundling step. This usually is not required unless you are using new experimental features that are only supported by typescript'stsc
compiler. One example of such feature isemitDecoratorMetadata
.- Returns:
this
-
sourceMap
Sets the value ofBundlingOptions.getSourceMap()
- Parameters:
sourceMap
- Whether to include source maps when bundling.- Returns:
this
-
sourceMapMode
Sets the value ofBundlingOptions.getSourceMapMode()
- Parameters:
sourceMapMode
- Source map mode to be used when bundling.- Returns:
this
-
sourcesContent
Sets the value ofBundlingOptions.getSourcesContent()
- Parameters:
sourcesContent
- Whether to include original source code in source maps when bundling.- Returns:
this
-
target
Sets the value ofBundlingOptions.getTarget()
- Parameters:
target
- Target environment for the generated JavaScript code.- Returns:
this
-
tsconfig
Sets the value ofBundlingOptions.getTsconfig()
- Parameters:
tsconfig
- Normally the esbuild automatically discoverstsconfig.json
files and reads their contents during a build. However, you can also configure a customtsconfig.json
file to use instead.This is similar to entry path, you need to provide path to your custom
tsconfig.json
.This can be useful if you need to do multiple builds of the same code with different settings.
For example,
{ 'tsconfig': 'path/custom.tsconfig.json' }
.- Returns:
this
-
command
Sets the value ofDockerRunOptions.getCommand()
- Parameters:
command
- The command to run in the container.- Returns:
this
-
entrypoint
Sets the value ofDockerRunOptions.getEntrypoint()
- Parameters:
entrypoint
- The entrypoint to run in the container.- Returns:
this
-
environment
Sets the value ofDockerRunOptions.getEnvironment()
- Parameters:
environment
- The environment variables to pass to the container.- Returns:
this
-
network
Sets the value ofDockerRunOptions.getNetwork()
- Parameters:
network
- Docker Networking options.- Returns:
this
-
platform
Sets the value ofDockerRunOptions.getPlatform()
- Parameters:
platform
- Set platform if server is multi-platform capable. Requires Docker Engine API v1.38+. Example value:linux/amd64
- Returns:
this
-
securityOpt
Sets the value ofDockerRunOptions.getSecurityOpt()
- Parameters:
securityOpt
- Security configuration when running the docker container.- Returns:
this
-
user
Sets the value ofDockerRunOptions.getUser()
- Parameters:
user
- The user to use when running the container.- Returns:
this
-
volumes
Sets the value ofDockerRunOptions.getVolumes()
- Parameters:
volumes
- Docker volumes to mount.- Returns:
this
-
volumesFrom
Sets the value ofDockerRunOptions.getVolumesFrom()
- Parameters:
volumesFrom
- Where to mount the specified volumes from.- Returns:
this
-
workingDirectory
Sets the value ofDockerRunOptions.getWorkingDirectory()
- Parameters:
workingDirectory
- Working directory inside the container.- Returns:
this
-
build
Builds the configured instance.- Specified by:
build
in interfacesoftware.amazon.jsii.Builder<BundlingOptions>
- Returns:
- a new instance of
BundlingOptions
- Throws:
NullPointerException
- if any required attribute was not provided
-