Hello, I've already tried adding
dotenv.config()
and/or
dotenv.config({path: path.resolve(__dirname, '../.env'),});
However, with the variables having
PAYLOAD_PUBLIC
in front, it still returns
undefined
.
Prod server is using
yaml
, not
env
.
What would the best solution here be? I'm suspecting
.env vars
are needed when it builds, but we can't work like that. Should I just make an
api
endpoint to server the payload public
env vars
?
Ty.
@eddieDev One option is extending the exposed webpack configuration
And using the webpack env variable plugin
May work with YAML config?
hey @thisisnotchris something like this?
// customAdminBuild.js
const path = require('path');
// Tell Payload where to find your Payload config - can do it either here, or in package.json script
process.env.PAYLOAD_CONFIG_PATH = path.resolve(__dirname, 'src/payload.config.ts');
const { build } = require('payload/dist/bin/build');
const buildPayloadAdmin = async () => {
// Fetch your environment variables here
// And then run
build
build();
}
buildPayloadAdmin();
hmmm
It's worth a shot! I'm not super familiar with yaml
unfortunately, after some research, this wont work since we cant add env variables during the build. It is added after the build. 😦
@eddieDev but surely you can import the vars right?
hey @thisisnotchris . I couldn't apply the above since we build first and add env vars later. I Tried various things and came up with a solution. What I landed on was setting up a route to the backend to get the payload_public env var that I needed, then persisted the data using localStorage in the frontend. Not ideal, but it will do.
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.