|
1 | 1 | # compute-js-static-publish
|
2 | 2 | Static Publisher for Compute@Edge JavaScript
|
| 3 | + |
| 4 | +Easily run your React application generated with [`create-react-app`](https://create-react-app.dev/) on |
| 5 | +a [Compute@Edge service](https://developer.fastly.com/learning/compute/javascript/). |
| 6 | + |
| 7 | +`create-react-app` provides a simple-to-use platform for getting started developing React |
| 8 | +applications. When you need to deploy your app to the internet, why not deploy it to Fastly's |
| 9 | +blazing-fast Edge Computing Platform? |
| 10 | + |
| 11 | +## How it works |
| 12 | + |
| 13 | +1. Use Create React App to create your application. |
| 14 | + |
| 15 | +```shell |
| 16 | +npx create-react-app my-app |
| 17 | +``` |
| 18 | + |
| 19 | +2. Work on your app as normal. |
| 20 | + |
| 21 | +```shell |
| 22 | +cd my-app |
| 23 | +npm start |
| 24 | +``` |
| 25 | + |
| 26 | +3. When you're ready to deploy to Fastly, build your production bundle, then run `compute-js-static-publish`. |
| 27 | + |
| 28 | +```shell |
| 29 | +npm run build # create-react-app's build command |
| 30 | +npx @fastly/compute-js-static-publish |
| 31 | +``` |
| 32 | + |
| 33 | +This will make a `compute-js` subfolder and initialize it as a Compute@Edge JavaScript application. |
| 34 | +It will add a default `./src/index.js` file that serves the static files from your production bundle. |
| 35 | + |
| 36 | +4. Run your application using [Fastly's local development server](https://developer.fastly.com/learning/compute/testing/#running-a-local-testing-server). |
| 37 | + |
| 38 | +```shell |
| 39 | +cd ./compute-js |
| 40 | +npm install |
| 41 | +fastly compute serve |
| 42 | +``` |
| 43 | + |
| 44 | +5. When you're ready to go live, [deploy it to your Compute@Edge service](https://developer.fastly.com/reference/cli/compute/publish/). |
| 45 | + |
| 46 | +```shell |
| 47 | +fastly compute publish |
| 48 | +``` |
| 49 | + |
| 50 | +6. Each time you build your Compute@Edge project, `compute-js-static-publish` will run a process that scans your `./build` |
| 51 | + directory for changes and generates a new `./src/statics.js` file. |
| 52 | + |
| 53 | +You're free to modify the `./src/index.js` handler to suit your needs, such as to add your own API endpoints. |
| 54 | +This framework will not touch that file after creation. |
| 55 | + |
| 56 | +## Options |
| 57 | + |
| 58 | +```shell |
| 59 | +npx @fastly/compute-js-static-publish --public-path=./build --static-path=./build/static --output=./compute-js --spa |
| 60 | +``` |
| 61 | + |
| 62 | +| Option | Default | Description | |
| 63 | +|-----------------|------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
| 64 | +| `--public-path` | `./build` | The directory that contains the application's public files. All files in this directory and subdirectories will be served by your Compute@Edge handler. | |
| 65 | +| `--static-path` | `./build/static` | A subdirectory of `--public-path` that contains the application's static files. The files in this directory and subdirectories will be served with a 1 year cache. | |
| 66 | +| `--output` | `./compute-js` | The directory in which to create the Compute@Edge application. | |
| 67 | +| `--spa` | `false` | If true, then the Compute@Edge handler will serve `<public-path>/index.html` when the requested file does not match any of the files in `<public-path>`. Useful for apps that use [client-side routing](https://create-react-app.dev/docs/deployment#serving-apps-with-client-side-routing). | |
| 68 | + |
| 69 | +The path and spa flag will be written to a `static-publish.json` file, and is referenced by the `compute-js-build-static-loader` |
| 70 | +command that is run on each `build` of the Compute@Edge project (this runs as a part of the `prebuild` script in `package.json`). |
0 commit comments