Replies: 1 comment
-
Thoughts on naming conventionSnowpack helps improve development by leveraging the very best and latest of web tech standards, which is great! When it comes to naming environment variables, it seems that snowpack enforces a non-standard, albeit with the best of intentions. Fully support the sentiment and the idea to encourage best practices. However, forcing env variables to have the name of the bundler that happened to be used at the time leaks the bundling abstraction into the code. The complications this can
Why do the other apps do it?Seems that both Next.js and CRA have their own reasons. Next.js seems to be using the convention because they have to distinguish between server and client env variables, which seems isn't really an issue with snowpack. It is their attempt at mitigating security risks by relying on naming conventions, and avoiding confusion for users that routinely engage with a framework that caters to both server and client. Would probably be safer to handle security at the ci level, as it doesn't really stop anyone from adding secrets to those env vars. Although yes, they would be much easier to catch in a PR review. CRA seems to be using the convention as a namespace to avoid clashing with other env vars. Makes sense since there's a lot going on there that users don't really have fine-grained control over until they Therefore, can't see an overwhelming benefit in maintaining this convention. Improving docs around dotenv
Worth documenting which conventions are being used as it may be misleading users to think that only .env files are supported (as those are the only ones recommended by dotenvjs) while in reality the source code includes several of them and documents an alternate style for dotenv files. Perhaps we can get inspiration from CRA's docs for snowpack's? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
We can inject env vars by carefully naming them SNOWPACK_PUBLIC_* since #394 was merged. But I think this does not allow for enough flexibility. NextJS allows to set env variables via next.config.js (https://nextjs.org/docs/api-reference/next.config.js/environment-variables), and I'd suggest to add a similar option to snowpack.config.js buildOptions.env / devOptions.env.
What do you think?
An example: I'm using AWS CDK to execute
yarn build
of my website project, which uses snowpack to build the code. Instead of changing my CDK scripts environment variables (API_URI, GRAPHQL_URI, ..) with SNOWPACK_PUBLIC prefix, I'd like to keep the names and just have my snowpack.config.js file changed:Beta Was this translation helpful? Give feedback.
All reactions