# @cloudcomponents/cdk-static-website 中文文档

规范地址：https://npmcn.com/package/%40cloudcomponents/cdk-static-website/

版本：2\.2\.0
npm 元数据更新时间：2024-05-16T19:32:25.833Z
中文译文更新时间：2026-11-10T09:19:03.082Z
软件包许可：MIT

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

原始 npm 页面：https://www.npmjs.com/package/%40cloudcomponents/cdk-static-website
原文对照：https://npmcn.com/package/%40cloudcomponents/cdk-static-website/?lang=original
项目主页：https://github.com/cloudcomponents/cdk-constructs
源码仓库：https://github.com/cloudcomponents/cdk-constructs

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

- 包体积（解压后）：1.2 MB，11 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- 运行依赖：0 个
- peer 依赖：aws-cdk-lib ^2\.141\.0，constructs ^10\.3\.0
- 首次发布：2019-01-20T13:52:52.134Z
- 最新版本发布：2024-05-16T19:32:25.604Z
- 近 30 天下载量：1887（2026-10-10 至 2026-11-08，npm 官方下载统计）
- 已发布版本数：137（近 12 个月 0 个）

## 中文简介

使用 S3 创建静态网站的 Cdk 组件, 配置 CloudFront( CDN) , 并通过 Route 53( DNS) 绘制自定义域名

## 安装

```sh
npm install @cloudcomponents/cdk-static-website
```

也可以使用：`pnpm add @cloudcomponents/cdk-static-website`、`yarn add @cloudcomponents/cdk-static-website`、`bun add @cloudcomponents/cdk-static-website`

## README

[![cloudcomponents Logo](https://raw.githubusercontent.com/cloudcomponents/cdk-constructs/master/logo.png)](https://github.com/cloudcomponents/cdk-constructs)

# @ cloud 组件/ cdk- static- website

[![Build Status](https://github.com/cloudcomponents/cdk-constructs/workflows/Build/badge.svg)](https://github.com/cloudcomponents/cdk-constructs/actions?query=workflow=Build) [![cdkdx](https://img.shields.io/badge/buildtool-cdkdx-blue.svg)](https://github.com/hupe1980/cdkdx) [![typescript](https://img.shields.io/badge/jsii-typescript-blueviolet.svg)](https://www.npmjs.com/package/@cloudcomponents/cdk-static-website) [![python](https://img.shields.io/badge/jsii-python-blueviolet.svg)](https://pypi.org/project/cloudcomponents.cdk-static-website/) [![Mentioned in Awesome CDK](https://awesome.re/mentioned-badge.svg)](https://github.com/kolomied/awesome-cdk)

> 使用 S3 创建静态网站的 Cdk 组件, 配置 CloudFront( CDN) , 并通过 Route 53( DNS) 绘制自定义域名

## 安装

类型脚本/ Java 脚本 :

```bash
npm i @cloudcomponents/cdk-static-website
```

Python : (中文(简体) )

```bash
pip install cloudcomponents.cdk-static-website
```

## 如何使用

```typescript
import { StaticWebsite } from '@cloudcomponents/cdk-static-website';
import { RemovalPolicy, Stack, StackProps, aws_route53 } from 'aws-cdk-lib';
import { Construct } from 'constructs';

export class StaticWebsiteStack extends Stack {
  constructor(scope: Construct, id: string, props: StackProps) {
    super(scope, id, props);

    const hostedZone = aws_route53.HostedZone.fromLookup(this, 'HostedZone', {
      domainName: 'cloudcomponents.org',
    });

    new StaticWebsite(this, 'StaticWebsite', {
      hostedZone,
      domainNames: ['cloudcomponents.org', 'www.cloudcomponents.org'],
      removalPolicy: RemovalPolicy.DESTROY,
    });
  }
}
```

### 单页应用程序( SPA)

```typescript
import { StaticWebsite } from '@cloudcomponents/cdk-static-website';
import { RemovalPolicy, Stack, StackProps, aws_route53 } from 'aws-cdk-lib';
import { Construct } from 'constructs';

export class StaticWebsiteStack extends Stack {
  constructor(scope: Construct, id: string, props: StackProps) {
    super(scope, id, props);

    const hostedZone = aws_route53.HostedZone.fromLookup(this, 'HostedZone', {
      domainName: 'cloudcomponents.org',
    });

    new StaticWebsite(this, 'StaticWebsite', {
      hostedZone,
      domainNames: ['cloudcomponents.org', 'www.cloudcomponents.org'],
      errorResponses: [
        {
          httpStatus: 404,
          responseHttpStatus: 200,
          ttl: props.ttl ?? Duration.seconds(300),
          responsePagePath: '/index.html',
        },
      ],
      removalPolicy: RemovalPolicy.DESTROY,
    });
  }
}
```

### 山姆达在边缘

```typescript
import { StaticWebsite } from '@cloudcomponents/cdk-static-website';
import { OriginMutation } from '@cloudcomponents/cdk-lambda-at-edge-pattern';
import { RemovalPolicy, Stack, StackProps, aws_route53 } from 'aws-cdk-lib';

import { Construct } from 'constructs';

export class StaticWebsiteStack extends Stack {
  constructor(scope: Construct, id: string, props: StackProps) {
    super(scope, id, props);

    const hostedZone = aws_route53.HostedZone.fromLookup(this, 'HostedZone', {
      domainName: 'cloudcomponents.org',
    });

    const originMutation = new OriginMutation(stack, 'OriginMutation');

    new StaticWebsite(this, 'StaticWebsite', {
      hostedZone,
      domainNames: ['cloudcomponents.org', 'www.cloudcomponents.org'],
      edgeLambdas: [originMutation],
      removalPolicy: RemovalPolicy.DESTROY,
    });
  }
}
```

## API 参考

见 [API.md (英语)](https://github.com/cloudcomponents/cdk-constructs/tree/master/packages/cdk-static-website/API.md)。 。 。 .

## 示例

见更完整的 [实例](https://github.com/cloudcomponents/cdk-constructs/tree/master/examples)。 。 。 .

## 许可证

[麻省理工学院](https://github.com/cloudcomponents/cdk-constructs/tree/master/packages/cdk-static-website/LICENSE)

## 常见问题

### @cloudcomponents/cdk-static-website 是什么？

使用 S3 创建静态网站的 Cdk 组件, 配置 CloudFront\( CDN\) , 并通过 Route 53\( DNS\) 绘制自定义域名

### 如何安装 @cloudcomponents/cdk-static-website？

在项目目录运行 npm install @cloudcomponents/cdk-static-website，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：aws-cdk-lib（^2\.141\.0）、constructs（^10\.3\.0）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @cloudcomponents/cdk-static-website 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @cloudcomponents/cdk-static-website 支持 ESM 还是 CommonJS？

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

### @cloudcomponents/cdk-static-website 可以商用吗？

@cloudcomponents/cdk-static-website 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @cloudcomponents/cdk-static-website 的下载量有多少？

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

### @cloudcomponents/cdk-static-website 还在维护吗？

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

