@Generated(value="jsii-pacmak/1.74.0 (build 6d08790)", date="2023-03-14T16:25:30.121Z") @Stability(value=Stable) public interface BundlingOptions extends software.amazon.jsii.JsiiSerializable
Example:
NodejsFunction.Builder.create(this, "my-handler")
.bundling(BundlingOptions.builder()
.dockerImage(DockerImage.fromBuild("/path/to/Dockerfile"))
.build())
.build();
| Modifier and Type | Interface and Description |
|---|---|
static class |
BundlingOptions.Builder
A builder for
BundlingOptions |
static class |
BundlingOptions.Jsii$Proxy
An implementation for
BundlingOptions |
| Modifier and Type | Method and Description |
|---|---|
static BundlingOptions.Builder |
builder() |
default String |
getAssetHash()
Specify a custom hash for this asset.
|
default String |
getBanner()
Use this to insert an arbitrary string at the beginning of generated JavaScript files.
|
default Map<String,String> |
getBuildArgs()
Build arguments to pass when building the bundling image.
|
default Charset |
getCharset()
The charset to use for esbuild's output.
|
default ICommandHooks |
getCommandHooks()
Command hooks.
|
default Map<String,String> |
getDefine()
Replace global identifiers with constant expressions.
|
default DockerImage |
getDockerImage()
A custom bundling Docker image.
|
default Map<String,String> |
getEnvironment()
Environment variables defined when bundling runs.
|
default Map<String,Object> |
getEsbuildArgs()
Build arguments to pass into esbuild.
|
default String |
getEsbuildVersion()
The version of esbuild to use when running in a Docker container.
|
default List<String> |
getExternalModules()
A list of modules that should be considered as externals (already available in the runtime).
|
default String |
getFooter()
Use this to insert an arbitrary string at the end of generated JavaScript files.
|
default Boolean |
getForceDockerBundling()
Force bundling in a Docker container even if local bundling is possible.
|
default OutputFormat |
getFormat()
Output format for the generated JavaScript files.
|
default List<String> |
getInject()
This option allows you to automatically replace a global variable with an import from another file.
|
default Boolean |
getKeepNames()
Whether to preserve the original `name` values even in minified code.
|
default Map<String,String> |
getLoader()
Use loaders to change how a given input file is interpreted.
|
default LogLevel |
getLogLevel()
Log level for esbuild.
|
default List<String> |
getMainFields()
How to determine the entry point for modules.
|
default Boolean |
getMetafile()
This option tells esbuild to write out a JSON file relative to output directory with metadata about the build.
|
default Boolean |
getMinify()
Whether to minify files when bundling.
|
default List<String> |
getNodeModules()
A list of modules that should be installed instead of bundled.
|
default Boolean |
getPreCompilation()
Run compilation using tsc before running file through bundling step.
|
default Boolean |
getSourceMap()
Whether to include source maps when bundling.
|
default SourceMapMode |
getSourceMapMode()
Source map mode to be used when bundling.
|
default Boolean |
getSourcesContent()
Whether to include original source code in source maps when bundling.
|
default String |
getTarget()
Target environment for the generated JavaScript code.
|
default String |
getTsconfig()
Normally the esbuild automatically discovers `tsconfig.json` files and reads their contents during a build.
|
@Stability(value=Stable) @Nullable default String getAssetHash()
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.
Default: - asset hash is calculated based on the bundled output
@Stability(value=Stable) @Nullable default String getBanner()
This is similar to footer which inserts at the end instead of the beginning.
This is commonly used to insert comments:
Default: - no comments are passed
@Stability(value=Stable) @Nullable default Map<String,String> getBuildArgs()
Default: - no build arguments are passed
@Stability(value=Stable) @Nullable default Charset getCharset()
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.
Default: Charset.ASCII
@Stability(value=Stable) @Nullable default ICommandHooks getCommandHooks()
Default: - do not run additional commands
@Stability(value=Stable) @Nullable default Map<String,String> getDefine()
For example, { 'process.env.DEBUG': 'true' }.
Another example, { 'process.env.API_KEY': JSON.stringify('xxx-xxxx-xxx') }.
Default: - no replacements are made
@Stability(value=Stable) @Nullable default DockerImage getDockerImage()
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.
Default: - use the Docker image provided by
@Stability(value=Stable) @Nullable default Map<String,String> getEnvironment()
Default: - no environment variables are defined.
@Stability(value=Stable) @Nullable default Map<String,Object> getEsbuildArgs()
For example, to add the --log-limit flag:
new NodejsFunction(scope, id, {
...
bundling: {
esbuildArgs: {
"--log-limit": "0",
}
}
});
Default: - no additional esbuild arguments are passed
@Stability(value=Stable) @Nullable default String getEsbuildVersion()
Default: - latest v0
@Stability(value=Stable) @Nullable default List<String> getExternalModules()
Default: ['aws-sdk']
@Stability(value=Stable) @Nullable default String getFooter()
This is similar to banner which inserts at the beginning instead of the end.
This is commonly used to insert comments
Default: - no comments are passed
@Stability(value=Stable) @Nullable default Boolean getForceDockerBundling()
This is useful if your function relies on node modules
that should be installed (nodeModules) in a Lambda compatible
environment.
Default: false
@Stability(value=Stable) @Nullable default OutputFormat getFormat()
Default: OutputFormat.CJS
@Stability(value=Stable) @Nullable default List<String> getInject()
Default: - no code is injected
@Stability(value=Stable) @Nullable default Boolean getKeepNames()
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.
Default: false
@Stability(value=Stable) @Nullable default Map<String,String> getLoader()
Configuring a loader for a given file type lets you load that file type with
an import statement or a require call.
Default: - use esbuild default loaders
@Stability(value=Stable) @Nullable default LogLevel getLogLevel()
This is also propagated to the package manager and applies to its specific install command.
Default: LogLevel.WARNING
@Stability(value=Stable) @Nullable default List<String> getMainFields()
Try ['module', 'main'] to default to ES module versions.
Default: ['main', 'module']
@Stability(value=Stable) @Nullable default Boolean getMetafile()
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.
Default: false
@Stability(value=Stable) @Nullable default Boolean getMinify()
Default: false
@Stability(value=Stable) @Nullable default List<String> getNodeModules()
Modules are installed in a Lambda compatible environment only when bundling runs in Docker.
Default: - all modules are bundled
@Stability(value=Stable) @Nullable default Boolean getPreCompilation()
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.
Default: false
@Stability(value=Stable) @Nullable default Boolean getSourceMap()
Default: false
@Stability(value=Stable) @Nullable default SourceMapMode getSourceMapMode()
Default: SourceMapMode.DEFAULT
@Stability(value=Stable) @Nullable default Boolean getSourcesContent()
Default: true
@Stability(value=Stable) @Nullable default String getTarget()
Default: - the node version of the runtime
@Stability(value=Stable) @Nullable default String getTsconfig()
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' }.
Default: - automatically discovered by `esbuild`
@Stability(value=Stable) static BundlingOptions.Builder builder()
BundlingOptions.Builder of BundlingOptionsCopyright © 2023. All rights reserved.