Scripts and Config for Runtime Env #2

Closed
telackey wants to merge 6 commits from telackey/runtimeenv into main
Member

This uses a combination of scripts, and webpack.DefinePlugin to automatically replace any references to process.env.FOO at runtime.

Normally, these get baked in during the build process, but under this scheme the reference gets replaced with a unique string at build time, and then replaced again with the environment value at runtime.

The runtime script operates on a copy of the code, so that the server can be restarted and the values updated each time.

❯ CERC_WEBAPP_DEBUG=1 yarn start
yarn run v1.22.19
$ yarn load-env && next start .next-r
$ scripts/replace-env.sh .next .next-r
CERC_TEST_WEBAPP_CONFIG1=this string
CERC_TEST_WEBAPP_CONFIG2=this different string
CERC_WEBAPP_DEBUG=1
   ▲ Next.js 14.0.1
   - Local:        http://localhost:3000

 ✓ Ready in 518ms
❯ CERC_WEBAPP_DEBUG=2 yarn start
yarn run v1.22.19
$ yarn load-env && next start .next-r
$ scripts/replace-env.sh .next .next-r
CERC_TEST_WEBAPP_CONFIG1=this string
CERC_TEST_WEBAPP_CONFIG2=this different string
CERC_WEBAPP_DEBUG=2
   ▲ Next.js 14.0.1
   - Local:        http://localhost:3000

 ✓ Ready in 517ms
This uses a combination of scripts, and webpack.DefinePlugin to automatically replace any references to `process.env.FOO` at runtime. Normally, these get baked in during the build process, but under this scheme the reference gets replaced with a unique string at build time, and then replaced again with the environment value at runtime. The runtime script operates on a copy of the code, so that the server can be restarted and the values updated each time. ``` ❯ CERC_WEBAPP_DEBUG=1 yarn start yarn run v1.22.19 $ yarn load-env && next start .next-r $ scripts/replace-env.sh .next .next-r CERC_TEST_WEBAPP_CONFIG1=this string CERC_TEST_WEBAPP_CONFIG2=this different string CERC_WEBAPP_DEBUG=1 ▲ Next.js 14.0.1 - Local: http://localhost:3000 ✓ Ready in 518ms ``` ``` ❯ CERC_WEBAPP_DEBUG=2 yarn start yarn run v1.22.19 $ yarn load-env && next start .next-r $ scripts/replace-env.sh .next .next-r CERC_TEST_WEBAPP_CONFIG1=this string CERC_TEST_WEBAPP_CONFIG2=this different string CERC_WEBAPP_DEBUG=2 ▲ Next.js 14.0.1 - Local: http://localhost:3000 ✓ Ready in 517ms ```
telackey added 3 commits 2023-11-07 04:31:53 +00:00
telackey added 1 commit 2023-11-07 04:37:40 +00:00
telackey added 1 commit 2023-11-07 04:46:40 +00:00
telackey requested review from dboreham 2023-11-07 04:47:52 +00:00
telackey added 1 commit 2023-11-07 04:48:59 +00:00
telackey closed this pull request 2023-11-08 00:28:56 +00:00
telackey deleted branch telackey/runtimeenv 2023-11-08 00:29:07 +00:00

Pull request closed

Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: cerc-io/test-progressive-web-app#2
No description provided.