@architect/plugin-typescript
架构架构的 TypeScript 支持和工作流程集成
安装
进入您现有的建筑师项目 :
npm i @architect/plugin-typescript --save-dev
在您的建筑师项目列表中添加以下内容( 通常是) app.arc:
@aws
runtime typescript # sets TS as the the default runtime for your entire project
@plugins
architect/plugin-typescript
或者,如果你愿意加入一个单一的TS Lambda开始, 放弃上面的内容 runtime typescript 在项目清单中设置,并在一个Lambda中添加以下内容:
# src/http/get-index/config.arc
@aws
runtime typescript
使用量
现在,简单的写作者 和Lambdas在其中 src 树为 index.ts 管理者。 例如:
// src/http/get-index/index.ts
import { Context, APIGatewayProxyResult, APIGatewayEvent } from 'aws-lambda'
export const handler = async (event: APIGatewayEvent, context: Context): Promise<APIGatewayProxyResult> => {
console.log(`Event:`, event)
console.log(`Context:`, context)
return { statusCode: 200, body: JSON.stringify({ message: 'Hello world!' }) }
}
上述功能将由建筑师自动转录到 ./.build/http/get-index.js(目的地构建目录可配置, 见下文. ) (中文(简体) )
当本地工作时, Sandbox 自动检测您的 TypeScript 处理器的更改, 并为您重新传送它们 .
配置
tsconfig.json
默认情况下, 建筑师 TypeScript 会通过您的 tsconfig.json 与转接者同在,esbuild[^1].
如果你有一个独特的 tsconfig.json file for a single Lambda (例如:. src/http/get-index/tsconfig.json),此选项将优先于您项目根部中的项目级别 TSConfig .
项目列表设置
下列更高层次的设置也可在您的建筑师项目列表中找到: @typescript 设置 pragma :
build- 自定义构建目录;默认为.build- 注意: 确保您将此目录添加到您的
.gitignore
- 注意: 确保您将此目录添加到您的
sourcemaps- 启用架构环境的源图;默认为testing+ 键staging- 清单
testing, (中文(简体) ),staging,和(或)production在环境中添加源图,或禁用所有源图false - 我们强烈建议您不要在您的
production环境,因为它可能对最终用户的性能和冷启动时间产生有意义的影响
- 清单
esbuild-config- 添加任意 新建配置 选项- 值是一个 CJS 文件的相对路径, 它导出一个构建对象选项; 这些选项将传递给构建
- 与此插件默认相冲突的任何选项都会被忽略
base-runtime- 设置不同的节点.js版本;默认为nodejs20.x
示例
@typescript
# Build into `./dist`
build dist
# Disable sourcemaps in `staging`, but add them to `production`; you probably shouldn't actually do this though
sourcemaps testing production
# Add esbuild plugins
esbuild-config esbuild-config.js
# Set the Lambda base runtime to Node.js 18
base-runtime nodejs18.x
洞穴
建筑设计 TypeScript, 它使用 esbuild,捆绑到 CommonJS 以避免围绕 需要转换到具有二等动态的无害环境管理然而,由于目前 在 Esbuilding 、 TypeScript 、 V8 等上层等待的问题.,顶级等待尚未支持.
如果您需要顶级等待, 我们建议暂时用普通 JavaScript 编写 .
[^1]:请到这里了解更多信息 怎么样 esbuild 使用 TSFig 系统