@fastly/compute-js-static-publish

中文文档
8.0.2发布于 2026/11/16MITTypeScriptES Module构建来源已验证近 30 天下载 8140

Static Publisher for Fastly Compute JavaScript

原始使用文档
文档目录7 节
  1. Quick Start
  2. 🔧 Local Preview
  3. 🚀 Deploy to Production
  4. Features
  5. Documentation
  6. Security issues
  7. License

@fastly/compute-js-static-publish

Fastly Compute + KV Store for static websites and web apps.

This CLI tool helps you:

  • ✅ Deploy static sites to Fastly Compute with zero backend
  • 📦 Store files in Fastly KV Store efficiently
    • 🎁 New in v8: Support for S3-compatible storage such as Fastly Object Storage (Beta)
  • 🗂 Publish to named collections (live, preview-42, etc.)
  • 🔄 Switch between collections at runtime
  • 🧹 Clean up old or expired assets

Quick Start

Create a directory for your project, place your static files in ./public, then type:

npx @fastly/compute-js-static-publish@latest --root-dir=./public --kv-store-name=site-content

New in v8: S3-compatible storage (such as Fastly Object Storage) is also supported (Beta). To use this mode, type:

npx @fastly/compute-js-static-publish@latest --root-dir=./public --storage-mode=s3 --s3-region=<region> --s3-bucket=<bucket-name>

If the storage needs a custom endpoint, as Fastly Object Storage does, add --s3-endpoint=<endpoint> (for example, --s3-endpoint=https://us-east-1.object.fastlystorage.app).

For more details, see the S3-compatible storage section in the full documentation.

🔧 Local Preview

cd compute-js
npm install
npm run dev:publish  # 'publish' your files to the simulated local KV Store
npm run dev:start    # preview locally

Serves your app at http://127.0.0.1:7676. If the app is using the KV Store, your content is served from a simulated KV Store managed by the development server.

If the app uses S3-compatible storage, use npm run s3:publish in place of npm run dev:publish. This uploads your files to the bucket. Set the S3_ACCESS_KEY_ID and S3_SECRET_ACCESS_KEY environment variables before you run s3:publish and dev:start.

🚀 Deploy to Production

When you're ready to go live, create a free Fastly account if you haven't already, and then:

cd compute-js
npm run fastly:deploy        # deploy the app
npm run fastly:publish       # upload your static files

fastly:publish needs a Fastly API token that can write to the KV Store. Set the FASTLY_API_TOKEN environment variable, or add -- --fastly-api-token=<token>. The command does not read the token of your Fastly CLI profile. If you are logged in with the Fastly CLI, you can give it that token:

FASTLY_API_TOKEN=$(npx fastly auth token) npm run fastly:publish

In the future, unless you have further changes to make to your app itself, you can upload further updates to your static files:

cd compute-js
npm run fastly:publish       # upload your static files

If the app uses S3-compatible storage, your files are already in the bucket after npm run s3:publish. Run npm run fastly:deploy to deploy the app, and use npm run s3:publish to upload updates. After the deploy, fastly.toml has the service ID, so s3:publish also purges the service's cache. For this purge, set FASTLY_API_TOKEN too. Without it, s3:publish stops with an error before it uploads files.

Features

  • Named collections for previews, staging, production
  • SPA + fallback handling
  • Precompressed Brotli/gzip support
  • CLI tools for publish, promote, and cleanup

Documentation

📘 This package includes the full documentation in DOCUMENTATION.md, with the CLI reference for this version. It is also available on GitHub:
https://github.com/fastly/compute-js-static-publish/tree/main

Security issues

Please see our SECURITY.md for guidance on reporting security-related issues.

License

MIT.

版本与发布记录

@fastly/compute-js-static-publish 共发布 105 个版本,首次发布于 2022/07/14;过去 12 个月发布了 34 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
8.0.2latest2026/11/16今天
8.1.0-beta.6beta2026/11/16今天
8.1.0-beta.52026/11/142 天前
8.1.0-beta.42026/11/133 天前
8.1.0-beta.32026/11/115 天前
8.1.0-beta.22026/11/106 天前

其他发布通道:latest-v7 → 7.0.9,beta → 8.1.0-beta.6。

关于 @fastly/compute-js-static-publish 的常见问题

@fastly/compute-js-static-publish 是什么?

Static Publisher for Fastly Compute JavaScript

如何安装 @fastly/compute-js-static-publish?

在项目目录运行 npm install @fastly/compute-js-static-publish,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@fastly/js-compute(^3.33.2 || ^4.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。它还提供命令行工具 compute-js-static-publish,可以用 npx compute-js-static-publish 直接运行。

@fastly/compute-js-static-publish 支持 TypeScript 吗?

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

@fastly/compute-js-static-publish 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@fastly/compute-js-static-publish 需要什么版本的 Node.js?

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

@fastly/compute-js-static-publish 可以商用吗?

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

@fastly/compute-js-static-publish 的下载量有多少?

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

@fastly/compute-js-static-publish 还在维护吗?

最新版本 8.0.2 发布于 2026/11/16(今天);至今共发布 105 个版本,其中过去 12 个月发布了 34 个;首次发布于 2022/07/14。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。