@cloudcomponents/cdk-static-website

中文文档
2.2.0发布于 2024/05/17MITTypeScriptCommonJS零依赖近 30 天下载 1887

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

中文使用文档
文档目录7 节
  1. 安装
  2. 如何使用
  3. 单页应用程序( SPA)
  4. 山姆达在边缘
  5. API 参考
  6. 示例
  7. 许可证

cloudcomponents Logo

@ cloud 组件/ cdk- static- website

Build Status cdkdx typescript python Mentioned in Awesome CDK

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

安装

类型脚本/ Java 脚本 :

npm i @cloudcomponents/cdk-static-website

Python : (中文(简体) )

pip install cloudcomponents.cdk-static-website

如何使用

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)

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,
    });
  }
}

山姆达在边缘

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 (英语)。 。 。 .

示例

见更完整的 实例。 。 。 .

许可证

麻省理工学院

版本与发布记录

@cloudcomponents/cdk-static-website 共发布 137 个版本,首次发布于 2019/01/20;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.2.0latest2024/05/172 年前
2.1.02024/03/262 年前
2.0.02022/03/164 年前
1.50.02022/01/224 年前
1.49.02022/01/144 年前
1.48.02021/11/244 年前

关于 @cloudcomponents/cdk-static-website 的常见问题

@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 和提交记录判断。