You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In issue #2540 I've noticed that it would be good to have a way to "inject" variables into the environment. The use-case of the issue is "adding package.json version to the app".
I'd like to add it to the dotenv plugin and wanted to know if my design would be OK. It could be also added as a separate plugin but I think an option in dotenv would be better.
I think passing a plugin option to dotenv should work and with the following line it could be added:
env is a object like { version: "1.2.3" }. That object can be created in snowpack.config.js by importing the version from package.json.
The result in import.meta for {env: { VERSION: "1.2.3" }} option would look like in the below screenshot:
I have this almost ready but I'd like to have some feedback on the below points before opening a PR.
Discussion
Only adding to SNOWPACK_PUBLIC env.: Is it OK to have just one option like env that will be added to SNOWPACK_PUBLIC? Or should it be possible to add it with-out that prefix?
Casing: I would add the env casing as it is passed to the option. Or should it be converted to upper-case? e.g. SNOWPACK_PUBLIC_version vs. SNOWPACK_PUBLIC_VERSION - I prefer the first one
Automatic version key: The version could be automatically added to the environment similar to MODE: 'development'. But I think it's too app-specific and it's OK for the user to add it in the config.
NODE_ENV/MODE for injection control: Should there be a way to have different injections? So it's possible to have different variables during development than in production build e.g. a message that will be added only during development would be a good example (like "DEV page")
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
In issue #2540 I've noticed that it would be good to have a way to "inject" variables into the environment. The use-case of the issue is "adding package.json version to the app".
I'd like to add it to the dotenv plugin and wanted to know if my design would be OK. It could be also added as a separate plugin but I think an option in dotenv would be better.
I think passing a plugin option to dotenv should work and with the following line it could be added:
env
is a object like{ version: "1.2.3" }
. That object can be created insnowpack.config.js
by importing the version frompackage.json
.The result in

import.meta
for{env: { VERSION: "1.2.3" }}
option would look like in the below screenshot:I have this almost ready but I'd like to have some feedback on the below points before opening a PR.
Discussion
env
that will be added toSNOWPACK_PUBLIC
? Or should it be possible to add it with-out that prefix?MODE: 'development'
. But I think it's too app-specific and it's OK for the user to add it in the config.Beta Was this translation helpful? Give feedback.
All reactions