astro/packages/integrations/mdx/test/fixtures/mdx-vite-env-vars/src/pages/vite-env-vars.mdx
Ben Holmes 58a2dca228
Fix: correctly transform import.meta.env.* in MDX (#4858)
* fix: serialize route pattern for Netlify edge

Co-authored-by: Jackie Macharia <jackiewmacharia>

* fix: escape import.meta.env in MDX compiler output

* test: env vars in mdx

* chore: changeset

* deps: estree-util-visit, @types/estree

* feat: inject import.meta.env w/ recma

* feat: pull importMetaEnv from vite + astro configs

* test: `import.meta.env` in JSX

* fix: lockfile

* chore: update changeset

* fix: remove stray stashed commit
2022-09-26 18:23:47 -04:00

38 lines
812 B
Text

---
title: Let's talk about my import.meta.env.SITE
---
export const modeWorks =
import.meta.env.MODE === 'production' ? 'MODE works' : 'MODE does not work!';
# About my import.meta.env.SITE
My `import.meta.env.SITE` is so cool, I can put env variables in code!
```js
const site = import.meta.env.SITE;
```
## But I can use import.meta.env properly too
<div data-env-site>
I can compute my site, for example: {new URL('/blog/cool-post', import.meta.env.SITE)}
</div>
<div data-env-variable-exports>
I can also use `import.meta.env` in variable exports: {modeWorks}
</div>
I can also use vars as HTML attributes:
<div
data-env-dump
data-env-prod={import.meta.env.PROD}
data-env-dev={import.meta.env.DEV}
data-env-base-url={import.meta.env.BASE_URL}
data-env-mode={import.meta.env.MODE}
></div>