-
-
Notifications
You must be signed in to change notification settings - Fork 540
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.
- Run the following command to generate an access token of Nx Cloud
npm install && npx nx g @nrwl/nx-cloud:init
- Note the value of
accessToken
innx.json
in the project root - Run the following command to delete
accessToken
fromnx.json
git checkout -- nx.json
- Open Nx Cloud in a browser and sign up and sign in
- Select "Connect a Workspace"
![](https://user-images.githubusercontent.com/1063435/215296989-296836ae-42f1-42d4-b238-696cbd261722.png)
- Select "Yes, I'm using @nrwl/nx-cloud" at "01 Check for Nx Cloud package"
![](https://user-images.githubusercontent.com/1063435/215296991-313ebd38-252a-40d7-9ef2-80ff33347a96.png)
- Select "Connect The Workspace" at "03 Setup The Access Token" and input the value of
accessToken
which you noted before
![](https://user-images.githubusercontent.com/1063435/215296993-3e407498-9202-435e-bd9c-e385ae4a5152.png)
- Select "View Your Workspace" and go back to the terminal
- 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>
- 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>
- Set the value of
accessToken
which you noted before to an environment variable asNX_CLOUD_ACCESS_TOKEN
, and confirm it
export NX_CLOUD_ACCESS_TOKEN=<The value of accessToken>
echo $NX_CLOUD_ACCESS_TOKEN
- Run the following command to generate the caches
npm run cache:fetch
- 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
- Open Nx Cloud in a browser and confirm whether the result is "Local Cache Hit"
![](https://user-images.githubusercontent.com/1063435/215297425-be6ce7cd-15be-46db-b7b0-278acde15970.png)
![](https://user-images.githubusercontent.com/1063435/215297426-c6292008-3268-4eac-8073-9484fbf0cae0.png)
- Open Cloudflare Pages and go to "Environment variables", set the value of
accessToken
asNX_CLOUD_ACCESS_TOKEN
into both Production and Preview
![](https://user-images.githubusercontent.com/1063435/216225421-a880846d-3683-478d-ad29-9e678a525d41.png)
- Go to the build settings
![](https://user-images.githubusercontent.com/1063435/215303878-d674cf07-86cf-4df7-8ea7-ecd3c693de7d.png)
- Change "Build command" as the following and save
npm run build:cached
![](https://user-images.githubusercontent.com/1063435/215303883-819ba65b-1dfd-4213-b4be-0e796af8d352.png)
- Push the branch to GitHub to deploy, and go to Nx Cloud to confirm whether the result is "Remote Cache Hit"
![](https://user-images.githubusercontent.com/1063435/215297683-450ef3e5-2938-4a37-9e4b-e9ae04d75a11.png)