fastpack icon indicating copy to clipboard operation
fastpack copied to clipboard

--globals option

Open zindel opened this issue 7 years ago • 8 comments

Some modules account for certain global variables to exist at runtime. The most known examples are global and process. This option would permit to specify the JavaScript file to populate all the global variables bundle may need. It will be included at very top of the bundle.

By default the value included would be:

global = window;
process = { env: {NODE_ENV: "<mode>"}};

Thoughts?

zindel avatar Mar 10 '18 10:03 zindel

@zindel the process.env.Node_env is a special case. Bundler like webpack and browsify usually replace them inline for dead code elimination

thangngoc89 avatar Mar 11 '18 23:03 thangngoc89

@thangngoc89 we're replacing process.env.NODE_ENV as well. Some modules account on existence of the process and/or process.env though. Maybe, we can omit the NODE_ENV part...

zindel avatar Mar 12 '18 07:03 zindel

@zindel then I think this is a reasonable approach

thangngoc89 avatar Mar 12 '18 11:03 thangngoc89

Is there currently any way to set environment variables through fpack?

boyswan avatar Sep 05 '18 14:09 boyswan

would automatically replacing process.env.X by the available environment variable at build time be considerable?

bloodyowl avatar Sep 06 '18 08:09 bloodyowl

@boyswan not at the moment. What is the use-case for them (except for NODE_ENV)?

@bloodyowl I am reluctant to add this functionality in this specific form since it breaks the predictability of the build. I.e. now we only consider the files & command line options as inputs. Adding environment variables will create the third "hidden" input source. Actually, the same question as above: what is the use-case for them?

zindel avatar Sep 06 '18 18:09 zindel

I use --mock flag to set configs with necessary options. Globals are always bad for isolation. process.env.NODE_ENV should be enough.

TrySound avatar Sep 06 '18 19:09 TrySound

@zindel the use case is often to pass flags (such as NODE_ENV) and environment information (such as API_URL) without having to write a special command for each environment.

bloodyowl avatar Sep 07 '18 08:09 bloodyowl