astro icon indicating copy to clipboard operation
astro copied to clipboard

🐛 BUG: Build fails because Vue Component cannot access the value set in vite define

Open hyakt opened this issue 2 years ago • 2 comments

What version of astro are you using?

1.0.0-beta.47

Are you using an SSR adapter? If so, which one?

None

What package manager are you using?

npm

What operating system are you using?

mac

Describe the Bug

Build fails because Vue Component cannot access the value set in vite define.

Works OK for astro dev. It is also OK if the vite define value is accessed from an Astro component.

image

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-njhw7j-328yrx?file=astro.config.mjs&file=src%2Fcomponents%2FSample.vue&file=src%2Fpages%2Findex.astro

Participation

  • [ ] I am willing to submit a pull request for this issue.

hyakt avatar Jun 18 '22 15:06 hyakt

I don't think Astro actually supports Vite's define config today, but need to confirm

In the meantime, as a workaround could something similar be done by importing a src/constants.js file or adding a script to the main layout similar to the example below?

---
const VERSION = '1.0.0';
---

<script define:vars={{ VERSION }}>
  window.__VERSION__ = VERSION;
</script>

tony-sull avatar Jun 20 '22 15:06 tony-sull

To add to this, as there may be a difference in perception, you can refer to the value of Vite's define if it is within the Astro Component. The problem is that you cannot access it from the Vue Component.

hyakt avatar Jun 21 '22 01:06 hyakt