@fastly/compute-js-static-publish 4.0.0-alpha.4 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -23
- package/build/cli/commands/init-app.d.ts.map +1 -1
- package/build/cli/commands/init-app.js +0 -1
- package/build/cli/index.js +2 -0
- package/build/cli/presets/implementations/astro.d.ts +7 -0
- package/build/cli/presets/implementations/astro.d.ts.map +1 -0
- package/build/cli/presets/implementations/astro.js +23 -0
- package/build/cli/presets/implementations/vue.d.ts +7 -0
- package/build/cli/presets/implementations/vue.d.ts.map +1 -0
- package/build/cli/presets/implementations/vue.js +24 -0
- package/build/cli/presets/index.d.ts.map +1 -1
- package/build/cli/presets/index.js +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
PRO TIP - If you are viewing this README in GitHub, click the hamburger menu on the row right above this to see a Table
|
|
2
|
-
of Contents!
|
|
3
|
-
|
|
4
1
|
# Static Publisher for JavaScript on Compute@Edge
|
|
5
2
|
|
|
6
3
|
Using a static site generator to build your website? Do you simply need to serve some static files? With `compute-js-static-publish`, now you can deploy and serve everything from Fastly's blazing-fast [Compute@Edge](https://developer.fastly.com/learning/compute/).
|
|
@@ -16,6 +13,7 @@ Version 4 of this tool has some awesome new features:
|
|
|
16
13
|
- Support for publishing files that won't necessarily be served by `PublisherServer`. File contents are made available to your application–useful, e.g., for reading data written by third-party tools, etc.
|
|
17
14
|
- Makes content and metadata available to your application, via pre-package path/file.
|
|
18
15
|
- Support for loading JavaScript files as code into your Compute@Edge application.
|
|
16
|
+
- Added presets for [Vue](https://vuejs.org/) and [Astro](https://astro.build/).
|
|
19
17
|
|
|
20
18
|
If you wish to update to this version, you may need to re-scaffold your application, or follow the steps outlined in [MIGRATING.md](./MIGRATING.md).
|
|
21
19
|
|
|
@@ -140,13 +138,13 @@ Note that the files referenced by `--spa` and `--not-found-page` do not necessar
|
|
|
140
138
|
|
|
141
139
|
These arguments are used to populate the `fastly.toml` and `package.json` files of your Compute@Edge application.
|
|
142
140
|
|
|
143
|
-
| Option | Default | Description
|
|
144
|
-
|
|
145
|
-
| `name` | `name` from `package.json`, or `compute-js-static-site` | The name of your Compute@Edge application.
|
|
146
|
-
| `description` | `description` from `package.json`, or `Compute@Edge static site` | The description of your Compute@Edge application.
|
|
147
|
-
| `author` | `author` from `package.json`, or `you@example.com` | The author of your Compute@Edge application.
|
|
148
|
-
| `service-id` | (None) | The ID of an existing Fastly WASM service for your Compute@Edge application.
|
|
149
|
-
| `object-store-name` | (None) | The name of
|
|
141
|
+
| Option | Default | Description |
|
|
142
|
+
|---------------------|------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
143
|
+
| `name` | `name` from `package.json`, or `compute-js-static-site` | The name of your Compute@Edge application. |
|
|
144
|
+
| `description` | `description` from `package.json`, or `Compute@Edge static site` | The description of your Compute@Edge application. |
|
|
145
|
+
| `author` | `author` from `package.json`, or `you@example.com` | The author of your Compute@Edge application. |
|
|
146
|
+
| `service-id` | (None) | The ID of an existing Fastly WASM service for your Compute@Edge application. |
|
|
147
|
+
| `object-store-name` | (None) | The name of an existing [Fastly Object Store](https://developer.fastly.com/learning/concepts/data-stores/#object-stores) to hold the content assets. In addition to already existing, it must be linked to the service specified by `--service-id`. |
|
|
150
148
|
|
|
151
149
|
## Usage with frameworks and static site generators
|
|
152
150
|
|
|
@@ -158,7 +156,9 @@ These arguments are used to populate the `fastly.toml` and `package.json` files
|
|
|
158
156
|
| `cra-eject` | `./build` | `./build/static` | For apps written using Create React App, but which have since been ejected via `npm run eject`. Does not check for `react-scripts`. |
|
|
159
157
|
| `vite` | `./dist` | (None) | For apps written using [Vite](https://vitejs.dev). |
|
|
160
158
|
| `sveltekit` | `./dist` | (None) | For apps written using [SvelteKit](https://kit.svelte.dev). |
|
|
159
|
+
| `vue` | `./dist` | (None) | For apps written using [Vue](https://vuejs.org), and that were created using [create-vue](https://github.com/vuejs/create-vue). |
|
|
161
160
|
| `next` | `./out` | (None) | For apps written using [Next.js](https://nextjs.org), using `npm run export`. *1 |
|
|
161
|
+
| `astro` | `./dist` | (None) | For apps written using [Astro](https://astro.build) (static apps only). *2 |
|
|
162
162
|
| `gatsby` | `./public` | (None) | For apps written using [Gatsby](https://www.gatsbyjs.com). |
|
|
163
163
|
| `docusaurus` | `./build` | (None) | For apps written using [Docusaurus](https://docusaurus.io) |
|
|
164
164
|
|
|
@@ -167,6 +167,8 @@ You may still override any of these options individually.
|
|
|
167
167
|
*1 - For Next.js, consider using `@fastly/next-compute-js`, a Next.js server implementation that allows you to run
|
|
168
168
|
your Next.js application on Compute@Edge.
|
|
169
169
|
|
|
170
|
+
*2 - Astro support does not support SSR.
|
|
171
|
+
|
|
170
172
|
## PublisherServer
|
|
171
173
|
|
|
172
174
|
`PublisherServer` is a simple yet powerful server that can be used out of the box to serve the files prepared by this tool.
|
|
@@ -208,20 +210,42 @@ For `compression`, the following values are allowed:
|
|
|
208
210
|
* `'br'` - Brotli
|
|
209
211
|
* `'gzip'` - Gzip
|
|
210
212
|
|
|
213
|
+
## Associating your project with a Fastly Service
|
|
214
|
+
|
|
215
|
+
The project created by this tool is a Fastly Compute@Edge JavaScript application, complete with a `fastly.toml` file that
|
|
216
|
+
describes your project to the Fastly CLI.
|
|
217
|
+
|
|
218
|
+
To deploy your project to production, you deploy it to a [Fastly service](https://developer.fastly.com/reference/glossary#term-service)
|
|
219
|
+
in your account. Usually, you create your service automatically as part of your first deployment of the project.
|
|
220
|
+
|
|
221
|
+
In this case, `fastly.toml` has no value for `service_id` at the time you deploy, so `fastly compute publish` will prompt
|
|
222
|
+
you to create a Fastly service in your account for you (afterwards saving the new service's ID to your `fastly.toml` file).
|
|
223
|
+
|
|
224
|
+
Alternatively, you may deploy to a service that already exists. You can create this service using the
|
|
225
|
+
[Fastly CLI](https://developer.fastly.com/reference/cli/service/create/) or the [Fastly web app](https://manage.fastly.com/).
|
|
226
|
+
Note that since this is a Compute@Edge application, the service must be created as a Wasm service.
|
|
227
|
+
|
|
228
|
+
Before deploying your application, specify the service by setting the `service_id` value in the `fastly.toml` file to the
|
|
229
|
+
ID of the service. The `fastly compute publish` will deploy to the service identified by this value.
|
|
230
|
+
|
|
231
|
+
To specify the service at the time you are scaffolding the project (for example, if you are running this tool and deploying
|
|
232
|
+
as part of a CI process), specify the `--service-id` command line argument to populate `fastly.toml` with this value.
|
|
233
|
+
|
|
211
234
|
## Using the Object Store (BETA) <a name="object-store"></a>
|
|
212
235
|
|
|
213
|
-
Starting with v4, it's now possible to upload assets to and serve them from a [Fastly Object Store](https://
|
|
236
|
+
Starting with v4, it's now possible to upload assets to and serve them from a [Fastly Object Store](https://developer.fastly.com/learning/concepts/data-stores/#object-stores).
|
|
214
237
|
|
|
215
|
-
|
|
216
|
-
|
|
238
|
+
You can enable the use of Object Store with `@fastly/compute-js-static-publish` as you scaffold your application, or
|
|
239
|
+
at any later time.
|
|
217
240
|
|
|
218
|
-
|
|
241
|
+
At the time you enable the use of Object Store:
|
|
219
242
|
|
|
220
|
-
*
|
|
221
|
-
compute publish` your application.
|
|
243
|
+
* Your Fastly service must already exist. See [Associating your project with a Fastly Service](#associating-your-project-with-a-fastly-service) above.
|
|
222
244
|
|
|
223
|
-
*
|
|
224
|
-
|
|
245
|
+
* Your Object Store must already exist under the same Fastly account, and be linked to the service.
|
|
246
|
+
As of this writing, to create the Object Store you will need to use either the Fastly CLI [fastly object-store create](https://developer.fastly.com/reference/cli/object-store/create/)
|
|
247
|
+
or the Fastly [Object Store API](https://developer.fastly.com/reference/api/services/resources/object-store/#create-store).
|
|
248
|
+
Once the Object Store is created, you must be link it to your Fastly service using the [Resource API](https://developer.fastly.com/reference/api/services/resource/#create-resource).
|
|
225
249
|
|
|
226
250
|
```shell
|
|
227
251
|
# Create an object store
|
|
@@ -231,13 +255,13 @@ $ curl -i -X POST "https://api.fastly.com/resources/stores/object" -H "Fastly-Ke
|
|
|
231
255
|
$ curl -i -X POST "https://api.fastly.com/service/YOUR_FASTLY_SERVICE_ID/version/YOUR_FASTLY_SERVICE_VERSION/resource" -H "Fastly-Key: YOUR_FASTLY_TOKEN" -H "Content-Type: application/x-www-form-urlencoded" -H "Accept: application/json" -d "name=example-store-service-a&resource_id=YOUR_OBJECT_STORE_ID"
|
|
232
256
|
```
|
|
233
257
|
|
|
234
|
-
Object Store
|
|
235
|
-
|
|
236
|
-
Resource API: https://developer.fastly.com/reference/api/services/resource/
|
|
237
|
-
|
|
238
|
-
* Once the Object Store is created and linked to your service, add its name to your `static-publish.rc.js`
|
|
258
|
+
Once the Object Store is created and linked to your service, add its name to your `static-publish.rc.js`
|
|
239
259
|
file under the `objectStore` key.
|
|
240
260
|
|
|
261
|
+
To specify the Object Store at the time you are scaffolding the project (for example, if you are running this tool and
|
|
262
|
+
deploying as part of a CI process), specify the `--service-id` and `--object-store-name` command line arguments to populate
|
|
263
|
+
the respective files with these values.
|
|
264
|
+
|
|
241
265
|
After you have done the above steps, go ahead and build your application as normal. If you use `fastly compute build --verbose`
|
|
242
266
|
(or run `npm run build` directly), you should see output in your logs saying that files are being sent to the Object Store.
|
|
243
267
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init-app.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/init-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAoPvD,wBAAgB,OAAO,CAAC,iBAAiB,EAAE,kBAAkB,
|
|
1
|
+
{"version":3,"file":"init-app.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/init-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAoPvD,wBAAgB,OAAO,CAAC,iBAAiB,EAAE,kBAAkB,QAka5D"}
|
|
@@ -467,7 +467,6 @@ ${fastlyServiceId != null ? `service_id = "${fastlyServiceId}"
|
|
|
467
467
|
fs.writeFileSync(fastlyTomlPath, fastlyTomlContent, "utf-8");
|
|
468
468
|
// static-publish.rc.js
|
|
469
469
|
const rootDirRel = path.relative(computeJsDir, rootDir);
|
|
470
|
-
const publicDirRel = path.relative(computeJsDir, publicDir);
|
|
471
470
|
// publicDirPrefix -- if public dir is deeper than the root dir, then
|
|
472
471
|
// public dir is used as a prefix to drill into asset names.
|
|
473
472
|
// e.g.,
|
package/build/cli/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"astro.d.ts","sourceRoot":"","sources":["../../../../src/cli/presets/implementations/astro.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE5D,qBAAa,WAAY,YAAW,WAAW;IAC7C,IAAI,SAAW;IACf,cAAc,EAAE,OAAO,CAAC,UAAU,CAAC,CAIjC;IACF,KAAK,CAAC,WAAW,EAAE,GAAG;CAavB"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export class AstroPreset {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.name = 'Astro';
|
|
4
|
+
this.defaultOptions = {
|
|
5
|
+
rootDir: './dist',
|
|
6
|
+
name: 'my-astro-app',
|
|
7
|
+
description: 'Compute@Edge static site from Astro',
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
check(packageJson) {
|
|
11
|
+
if (packageJson == null) {
|
|
12
|
+
console.error("❌ Can't read/parse package.json");
|
|
13
|
+
console.error("Run this from a Astro project directory.");
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
if (packageJson?.dependencies?.['astro'] == null) {
|
|
17
|
+
console.error("❌ Can't find astro in dependencies");
|
|
18
|
+
console.error("Run this from a Astro project directory.");
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vue.d.ts","sourceRoot":"","sources":["../../../../src/cli/presets/implementations/vue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE5D,qBAAa,SAAU,YAAW,WAAW;IAC3C,IAAI,SAAS;IACb,cAAc,EAAE,OAAO,CAAC,UAAU,CAAC,CAIjC;IACF,KAAK,CAAC,WAAW,EAAE,GAAG;CAcvB"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export class VuePreset {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.name = 'Vue';
|
|
4
|
+
this.defaultOptions = {
|
|
5
|
+
rootDir: './dist',
|
|
6
|
+
name: 'my-vue-app',
|
|
7
|
+
description: 'Compute@Edge static site from Vue (create-vue)',
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
check(packageJson) {
|
|
11
|
+
if (packageJson == null) {
|
|
12
|
+
console.error("❌ Can't read/parse package.json");
|
|
13
|
+
console.error("Run this from a Vue project directory created by create-vue.");
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
if (packageJson?.devDependencies?.['vite'] == null) {
|
|
17
|
+
console.error("❌ Can't find vite in dependencies");
|
|
18
|
+
console.error("Run this from a Vue project directory created by create-vue.");
|
|
19
|
+
console.log("If this is a project created with the Vue CLI, migrate it to use Vite first. Refer to the create-vue documentation at https://www.npmjs.com/package/create-vue (not authored or maintained by Fastly) for details on this process.");
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cli/presets/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cli/presets/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAU/C,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,UAAS,WAAW,CAWxD,CAAC"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { CreateReactAppPreset, CreateReactAppEjectedPreset } from './implementations/create-react-app.js';
|
|
2
2
|
import { VitePreset } from './implementations/vite.js';
|
|
3
3
|
import { SvelteKitPreset } from './implementations/sveltekit.js';
|
|
4
|
+
import { VuePreset } from './implementations/vue.js';
|
|
4
5
|
import { NextJsPreset } from './implementations/next.js';
|
|
6
|
+
import { AstroPreset } from "./implementations/astro.js";
|
|
5
7
|
import { GatsbyPreset } from './implementations/gatsby.js';
|
|
6
8
|
import { DocusaurusPreset } from './implementations/docusaurus.js';
|
|
7
9
|
export const presets = {
|
|
@@ -10,7 +12,9 @@ export const presets = {
|
|
|
10
12
|
'cra-eject': CreateReactAppEjectedPreset,
|
|
11
13
|
'vite': VitePreset,
|
|
12
14
|
'sveltekit': SvelteKitPreset,
|
|
15
|
+
'vue': VuePreset,
|
|
13
16
|
'next': NextJsPreset,
|
|
17
|
+
'astro': AstroPreset,
|
|
14
18
|
'gatsby': GatsbyPreset,
|
|
15
19
|
'docusaurus': DocusaurusPreset,
|
|
16
20
|
};
|
package/package.json
CHANGED