Skip to content

Commit

Permalink
feat(expose): add snowpack env var support
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Sep 21, 2021
1 parent 52822b1 commit bdd68e1
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions packages/expose/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// FIXME https://github.com/snowpackjs/snowpack/issues/3621#issuecomment-907731004
import.meta.hot;

declare const __SNOWPACK_ENV__: any;

/**
* Exposes given `value` as `id` in global scope, iff `always = true`
* (default: false) or if `process.env.NODE_ENV != "production"` or if the
Expand All @@ -17,15 +22,16 @@ export const exposeGlobal = (id: string, value: any, always = false) => {
if (
glob &&
(always ||
(() => {
try {
return (
process.env.NODE_ENV !== "production" ||
process.env.UMBRELLA_GLOBALS === "1"
);
} catch (e) {}
return false;
})())
(() =>
typeof process !== "undefined" &&
typeof process.env !== "undefined"
? process.env.NODE_ENV !== "production" ||
!!process.env.UMBRELLA_GLOBALS
: typeof __SNOWPACK_ENV__ !== "undefined"
? __SNOWPACK_ENV__.MODE !== "production" ||
!!__SNOWPACK_ENV__.UMBRELLA_GLOBALS ||
!!__SNOWPACK_ENV__.SNOWPACK_PUBLIC_UMBRELLA_GLOBALS
: true)())
) {
glob[id] = value;
}
Expand Down

0 comments on commit bdd68e1

Please sign in to comment.