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
Not sure if you like the idea but ive written this - https://github.com/Andarist/rollup-plugin-dotenv . Inspired by CRA which uses .env files to keep env vars organised (sorry that my plugin has no README 😉 yet...)
@Andarist looks nice - it also supports inlining regular env vars? Could always have both.
It doesn't - mainly because:
without special casing (like ur --define proposal) it's hard to tell which env vars should be used and I didnt want to include everything that can be found on process.env
when bundling libraries I don't want to have NODE_ENV replaced (leaving that to consumers, so a library can differentiate between dev/prod code paths)
It does support overriding with env vars what is specified in .env files though.
Makes sense. That being said, rollup's syntax is pretty much what I'm in need of - I have 2 builds from the same source, but want to define a variable that changes the output. Basically something like #ifdef:
// a bunch of theseif(PRETTY){// whitespace handling stuff here}
if u have bunch of such variables (btw what they are? if thats not a mystery) it's imho good to gather them in .env files (which can act like a presets of different sets of those vars)
in the future i'd like to add special env vars to microbundle (need to rethink how it should work exactly) - such as REACT, PREACT, SERVER, NATIVE, BROWSER - multiple bundles could be outputted based on used package.json keys or smth.
I understand though that for other use cases than those from last paragraph and when having just 1 or 2 variables it's easier to use --define than creating .env files. Although I don't like rollup's syntax I'd prefer using it just to align to it as microbundle is built on top of rollup anyway and should be easier to explain this option (we could link to rollup's docs).
I came here to see if this feature existed 👍 Would love it.
To keep it simple, you could use --replace instead of --define to indicate that we're doing variable replacement and that it's not related to environment variables. Otherwise people might also expect that they can check against process.env.NODE_ENV.
I'm fine with the .env files, just it seems like it would make sense to support both. Presumably there's already a way to hydrate environment variables from a .env file like load-from-env .env microbundle?
In my opinion this should have been done in the initial release. Tell me, please, how can I implement this manually, until this feature is implemented?
One thing to be cautious of is that if you expose all environment variables, one could accidentally leak credentials if they have just process.env in their code. Create React App requires env variables to be prefixed with REACT_APP_ for this reason.
Activity
ForsakenHarmony commentedon Aug 1, 2018
creator makes a feature request 👀
Andarist commentedon Aug 1, 2018
Not sure if you like the idea but ive written this - https://github.com/Andarist/rollup-plugin-dotenv . Inspired by CRA which uses .env files to keep env vars organised (sorry that my plugin has no README 😉 yet...)
developit commentedon Aug 1, 2018
@Andarist looks nice - it also supports inlining regular env vars? Could always have both.
developit commentedon Aug 1, 2018
lol @ForsakenHarmony it was more of a "what do y'all think of this?" :P
Andarist commentedon Aug 2, 2018
It doesn't - mainly because:
--defineproposal) it's hard to tell which env vars should be used and I didnt want to include everything that can be found onprocess.envNODE_ENVreplaced (leaving that to consumers, so a library can differentiate between dev/prod code paths)It does support overriding with env vars what is specified in .env files though.
BTW. rollup supports this:
Not a fun of that syntax though.
developit commentedon Aug 2, 2018
Makes sense. That being said, rollup's syntax is pretty much what I'm in need of - I have 2 builds from the same source, but want to define a variable that changes the output. Basically something like
#ifdef:Andarist commentedon Aug 2, 2018
if u have bunch of such variables (btw what they are? if thats not a mystery) it's imho good to gather them in .env files (which can act like a presets of different sets of those vars)
in the future i'd like to add special env vars to microbundle (need to rethink how it should work exactly) - such as REACT, PREACT, SERVER, NATIVE, BROWSER - multiple bundles could be outputted based on used
package.jsonkeys or smth.I understand though that for other use cases than those from last paragraph and when having just 1 or 2 variables it's easier to use
--definethan creating .env files. Although I don't like rollup's syntax I'd prefer using it just to align to it as microbundle is built on top of rollup anyway and should be easier to explain this option (we could link to rollup's docs).balloob commentedon Aug 7, 2018
I came here to see if this feature existed 👍 Would love it.
To keep it simple, you could use
--replaceinstead of--defineto indicate that we're doing variable replacement and that it's not related to environment variables. Otherwise people might also expect that they can check againstprocess.env.NODE_ENV.developit commentedon Aug 14, 2018
I'm fine with the
.envfiles, just it seems like it would make sense to support both. Presumably there's already a way to hydrate environment variables from a.envfile likeload-from-env .env microbundle?kutuluk commentedon Sep 18, 2018
In my opinion this should have been done in the initial release. Tell me, please, how can I implement this manually, until this feature is implemented?
kutuluk commentedon Sep 21, 2018
Can define through a .js file:
.env
definitions.js
where the initial definitions are taken from the command line
--defineballoob commentedon Sep 21, 2018
One thing to be cautious of is that if you expose all environment variables, one could accidentally leak credentials if they have just
process.envin their code. Create React App requires env variables to be prefixed withREACT_APP_for this reason.chopfitzroy commentedon Jul 27, 2020
Hey @developit I notice
--definehas been added, is it possible to define these values from an.envfile?developit commentedon Jul 30, 2020
Not currently, no.