-
Notifications
You must be signed in to change notification settings - Fork 361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: replace/define constants #181
Comments
creator makes a feature request 👀 |
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. |
lol @ForsakenHarmony it was more of a "what do y'all think of this?" :P |
It doesn't - mainly because:
It does support overriding with env vars what is specified in .env files though. BTW. rollup supports this: {
"scripts": {
"build": "rollup -c --environment INCLUDE_DEPS,BUILD:production"
}
} Not a fun of that syntax 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 // a bunch of these
if (PRETTY) {
// whitespace handling stuff here
} microbundle --define PRETTY=true && microbundle --define PRETTY=false |
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 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 |
I came here to see if this feature existed 👍 Would love it. To keep it simple, you could use |
I'm fine with the |
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? |
Can define through a .js file: .env
definitions.js import dotenv from 'dotenv';
dotenv.config();
export default definitions => {
definitions.PRETTY = true;
definitions.HOST = process.env.HOST;
definitions.DEVELOPMENT = process.env.NODE_ENV === 'development';
}; where the initial definitions are taken from the command line |
One thing to be cautious of is that if you expose all environment variables, one could accidentally leak credentials if they have just |
Hey @developit I notice |
Not currently, no. |
Usage:
Result:
input:
output with
--define NODE_ENV=production
:All we have to do is use rollup-plugin-replace to injec the value. Uglify handles the rest.
The text was updated successfully, but these errors were encountered: