Skip to content

Speed up buildings (for persons who has many posts)

Hiroki Toyokawa edited this page May 20, 2023 · 2 revisions

This section explains to speed up buildings for persons who has many posts.

Additional requirements

Steps

  1. Run the following command to generate an access token of Nx Cloud
npm install && npx nx g @nrwl/nx-cloud:init
  1. Note the value of accessToken in nx.json in the project root
  2. Run the following command to delete accessToken from nx.json
git checkout -- nx.json
  1. Open Nx Cloud in a browser and sign up and sign in
  2. Select "Connect a Workspace"
  1. Select "Yes, I'm using @nrwl/nx-cloud" at "01 Check for Nx Cloud package"
  1. Select "Connect The Workspace" at "03 Setup The Access Token" and input the value of accessToken which you noted before
  1. Select "View Your Workspace" and go back to the terminal
  2. Confirm NOTION_API_SECRET is set to an environment variable properly
echo $NOTION_API_SECRET

If not so, set your Notion API secret.

export NOTION_API_SECRET=<YOUR_NOTION_API_SECRET>
  1. Confirm DATABASE_ID environment variable is equivalent with the Cloudflare Pages building environment
echo $DATABASE_ID

Set the same value if it's not same.

export DATABASE_ID=<YOUR_DATABASE_ID>
  1. Set the value of accessToken which you noted before to an environment variable as NX_CLOUD_ACCESS_TOKEN, and confirm it
export NX_CLOUD_ACCESS_TOKEN=<The value of accessToken>
echo $NX_CLOUD_ACCESS_TOKEN
  1. Run the following command to generate the caches
npm run cache:fetch
  1. Run the command again to confirm whether the caches are generated (if the caches are generated properly, the command will be done faster than previous)
  • The caches will be updated automatically if last_edited_time of Notion Page are changed so you don't need to run the command after this confirmation
npm run cache:fetch
  1. Open Nx Cloud in a browser and confirm whether the result is "Local Cache Hit"
  1. Open Cloudflare Pages and go to "Environment variables", set the value of accessToken as NX_CLOUD_ACCESS_TOKEN into both Production and Preview
  1. Go to the build settings
  1. Change "Build command" as the following and save
npm run build:cached
  1. Push the branch to GitHub to deploy, and go to Nx Cloud to confirm whether the result is "Remote Cache Hit"