public static final class BundlingOptions.Builder
extends java.lang.Object
BundlingOptions
Constructor and Description |
---|
Builder() |
public BundlingOptions.Builder assetHash(java.lang.String assetHash)
BundlingOptions.getAssetHash()
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.
this
public BundlingOptions.Builder banner(java.lang.String banner)
BundlingOptions.getBanner()
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:
this
public BundlingOptions.Builder buildArgs(java.util.Map<java.lang.String,java.lang.String> buildArgs)
BundlingOptions.getBuildArgs()
buildArgs
- Build arguments to pass when building the bundling image.this
public BundlingOptions.Builder charset(Charset charset)
BundlingOptions.getCharset()
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
.this
public BundlingOptions.Builder commandHooks(ICommandHooks commandHooks)
BundlingOptions.getCommandHooks()
commandHooks
- Command hooks.this
public BundlingOptions.Builder define(java.util.Map<java.lang.String,java.lang.String> define)
BundlingOptions.getDefine()
define
- Replace global identifiers with constant expressions.
For example, { 'process.env.DEBUG': 'true' }
.
Another example, { 'process.env.API_KEY': JSON.stringify('xxx-xxxx-xxx') }
.
this
public BundlingOptions.Builder dockerImage(DockerImage dockerImage)
BundlingOptions.getDockerImage()
dockerImage
- A custom bundling Docker image.
This image should have esbuild installed globally. If you plan to use nodeModules
it should also have npm
or yarn
depending on the lock file you're using.
See https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/aws-lambda-nodejs/lib/Dockerfile for the default image provided by @aws-cdk/aws-lambda-nodejs.
this
public BundlingOptions.Builder environment(java.util.Map<java.lang.String,java.lang.String> environment)
BundlingOptions.getEnvironment()
environment
- Environment variables defined when bundling runs.this
public BundlingOptions.Builder esbuildArgs(java.util.Map<java.lang.String,? extends java.lang.Object> esbuildArgs)
BundlingOptions.getEsbuildArgs()
esbuildArgs
- Build arguments to pass into esbuild.
For example, to add the --log-limit flag:
new NodejsFunction(scope, id, { ... bundling: { esbuildArgs: { "--log-limit": "0", } } });
this
public BundlingOptions.Builder esbuildVersion(java.lang.String esbuildVersion)
BundlingOptions.getEsbuildVersion()
esbuildVersion
- The version of esbuild to use when running in a Docker container.this
public BundlingOptions.Builder externalModules(java.util.List<java.lang.String> externalModules)
BundlingOptions.getExternalModules()
externalModules
- A list of modules that should be considered as externals (already available in the runtime).this
public BundlingOptions.Builder footer(java.lang.String footer)
BundlingOptions.getFooter()
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
this
public BundlingOptions.Builder forceDockerBundling(java.lang.Boolean forceDockerBundling)
BundlingOptions.getForceDockerBundling()
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.this
public BundlingOptions.Builder format(OutputFormat format)
BundlingOptions.getFormat()
format
- Output format for the generated JavaScript files.this
public BundlingOptions.Builder inject(java.util.List<java.lang.String> inject)
BundlingOptions.getInject()
inject
- This option allows you to automatically replace a global variable with an import from another file.this
public BundlingOptions.Builder keepNames(java.lang.Boolean keepNames)
BundlingOptions.getKeepNames()
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.
this
public BundlingOptions.Builder loader(java.util.Map<java.lang.String,java.lang.String> loader)
BundlingOptions.getLoader()
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
an import
statement or a require
call.this
public BundlingOptions.Builder logLevel(LogLevel logLevel)
BundlingOptions.getLogLevel()
logLevel
- Log level for esbuild.
This is also propagated to the package manager and
applies to its specific install command.this
public BundlingOptions.Builder mainFields(java.util.List<java.lang.String> mainFields)
BundlingOptions.getMainFields()
mainFields
- How to determine the entry point for modules.
Try ['module', 'main'] to default to ES module versions.this
public BundlingOptions.Builder metafile(java.lang.Boolean metafile)
BundlingOptions.getMetafile()
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.
this
public BundlingOptions.Builder minify(java.lang.Boolean minify)
BundlingOptions.getMinify()
minify
- Whether to minify files when bundling.this
public BundlingOptions.Builder nodeModules(java.util.List<java.lang.String> nodeModules)
BundlingOptions.getNodeModules()
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.this
public BundlingOptions.Builder preCompilation(java.lang.Boolean preCompilation)
BundlingOptions.getPreCompilation()
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's tsc
compiler.
One example of such feature is emitDecoratorMetadata
.this
public BundlingOptions.Builder sourceMap(java.lang.Boolean sourceMap)
BundlingOptions.getSourceMap()
sourceMap
- Whether to include source maps when bundling.this
public BundlingOptions.Builder sourceMapMode(SourceMapMode sourceMapMode)
BundlingOptions.getSourceMapMode()
sourceMapMode
- Source map mode to be used when bundling.this
public BundlingOptions.Builder sourcesContent(java.lang.Boolean sourcesContent)
BundlingOptions.getSourcesContent()
sourcesContent
- Whether to include original source code in source maps when bundling.this
public BundlingOptions.Builder target(java.lang.String target)
BundlingOptions.getTarget()
target
- Target environment for the generated JavaScript code.this
public BundlingOptions.Builder tsconfig(java.lang.String tsconfig)
BundlingOptions.getTsconfig()
tsconfig
- Normally the esbuild automatically discovers `tsconfig.json` files and reads their contents during a build.
However, you can also configure a custom tsconfig.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' }
.
this
public BundlingOptions build()
BundlingOptions
java.lang.NullPointerException
- if any required attribute was not provided