# @architect/plugin-typescript 中文文档

规范地址：https://npmcn.com/package/%40architect/plugin-typescript/

版本：2\.1\.0
npm 元数据更新时间：2026-03-03T19:04:25.359Z
中文译文更新时间：2026-11-08T03:19:54.233Z
软件包许可：Apache-2\.0

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40architect/plugin-typescript
原文对照：https://npmcn.com/package/%40architect/plugin-typescript/?lang=original
项目主页：https://github.com/architect/plugin-typescript#readme
源码仓库：https://github.com/architect/plugin-typescript

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：13.1 kB，5 个文件
- 模块格式：CommonJS
- TypeScript 类型：未声明
- Node.js 要求：\>=14
- 运行依赖：3 个
- 首次发布：2022-01-18T18:58:42.794Z
- 最新版本发布：2024-03-26T21:24:02.578Z
- 近 30 天下载量：1915（2026-10-07 至 2026-11-05，npm 官方下载统计）
- 已发布版本数：17（近 12 个月 0 个）

## 中文简介

TypeScript 自定义运行时间+架构师工作流程集成

## 安装

```sh
npm install @architect/plugin-typescript
```

也可以使用：`pnpm add @architect/plugin-typescript`、`yarn add @architect/plugin-typescript`、`bun add @architect/plugin-typescript`

## README

![Architect Logo](https://github.com/architect/assets.arc.codes/raw/main/public/architect-logo-500b%402x.png)

## [`@architect/plugin-typescript`](https://www.npmjs.com/package/@architect/plugin-typescript)

> 架构架构的 TypeScript 支持和工作流程集成

[![GitHub CI status](https://github.com/architect/plugin-typescript/workflows/Node%20CI/badge.svg)](https://github.com/architect/plugin-typescript/actions?query=workflow%3A%22Node+CI%22)

## 安装

进入您现有的建筑师项目 :

```sh
npm i @architect/plugin-typescript --save-dev
```

在您的建筑师项目列表中添加以下内容( 通常是) `app.arc`:

```arc
@aws
runtime typescript # sets TS as the the default runtime for your entire project

@plugins
architect/plugin-typescript
```

或者,如果你愿意加入一个单一的TS Lambda开始, 放弃上面的内容 `runtime typescript` 在项目清单中设置,并在一个Lambda中添加以下内容:

```arc
# src/http/get-index/config.arc
@aws
runtime typescript
```

## 使用量

现在,简单的写作者 和Lambdas在其中 `src` 树为 `index.ts` 管理者。 例如:

```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`(目的地构建目录可配置, [见下文](https://npmcn.com/package/%40architect/plugin-typescript/#readme-configuration). ) (中文(简体) )

当本地工作时, Sandbox 自动检测您的 TypeScript 处理器的更改, 并为您重新传送它们 .

## 配置

### `tsconfig.json`

默认情况下, 建筑师 TypeScript 会通过您的 `tsconfig.json` 与转接者同在,[`esbuild`](https://esbuild.github.io/)\[^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` - 添加任意 [新建配置](https://esbuild.github.io/api/) 选项
    -   值是一个 CJS 文件的相对路径, 它导出一个构建对象选项; 这些选项将传递给构建
    -   与此插件默认相冲突的任何选项都会被忽略
-   `base-runtime` - 设置不同的节点.js版本;默认为 `nodejs20.x`
    -   见 [lambda 支持的节点运行时间列表](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html)

示例

```arc
@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`](https://esbuild.github.io/),捆绑到 CommonJS 以避免围绕 [需要转换到具有二等动态的无害环境管理](https://github.com/evanw/esbuild/issues/1921)然而,由于目前 [在 Esbuilding 、 TypeScript 、 V8 等上层等待的问题.](https://github.com/evanw/esbuild/issues/253),顶级等待尚未支持.

如果您需要顶级等待, 我们建议暂时用普通 JavaScript 编写 .

\[^1\]:请到这里了解更多信息 [怎么样 `esbuild` 使用 TSFig 系统](https://esbuild.github.io/api/#tsconfig)

## 常见问题

### @architect/plugin-typescript 是什么？

TypeScript 自定义运行时间\+架构师工作流程集成

### 如何安装 @architect/plugin-typescript？

在项目目录运行 npm install @architect/plugin-typescript，或使用 pnpm add / yarn add / bun add。

### @architect/plugin-typescript 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/architect\_\_plugin-typescript 是否存在。

### @architect/plugin-typescript 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @architect/plugin-typescript 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=14。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @architect/plugin-typescript 可以商用吗？

@architect/plugin-typescript 使用 Apache-2\.0 许可。宽松许可：允许商业使用、修改和再分发，并附带明确的专利授权；分发时需保留许可与 NOTICE 文件，修改过的文件要注明改动。以上为概括，不构成法律意见，请以许可原文为准。

### @architect/plugin-typescript 的下载量有多少？

根据 npm 官方下载统计，@architect/plugin-typescript 在 2026/10/07 – 2026/11/05 这 30 天内被下载 1,915 次，日均约 64 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @architect/plugin-typescript 还在维护吗？

最新版本 2\.1\.0 发布于 2024/03/27（2 年前）；至今共发布 17 个版本，其中过去 12 个月发布了 0 个；首次发布于 2022/01/19。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

