Skip to content
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

fix: support for define global constants #743

Merged
merged 9 commits into from Feb 13, 2022

Conversation

poyoho
Copy link
Member

@poyoho poyoho commented Feb 12, 2022

fix: #706

use vite load module and exec the module in the vm, the pr support the define var in the vm.

@netlify
Copy link

netlify bot commented Feb 12, 2022

✔️ Deploy Preview for vitest-dev ready!

🔨 Explore the source changes: 674fb04

🔍 Inspect the deploy log: https://app.netlify.com/sites/vitest-dev/deploys/6208b563b377250008847373

😎 Browse the preview: https://deploy-preview-743--vitest-dev.netlify.app

Copy link
Member

@sheremet-va sheremet-va left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you find the real reason why contant's weren't defined in Vue?

packages/vitest/src/node/execute.ts Outdated Show resolved Hide resolved
@sheremet-va
Copy link
Member

Also shouldn't they be statically replaced? And not just declared on a global?

@poyoho
Copy link
Member Author

poyoho commented Feb 13, 2022

Did you find the real reason why contant's weren't defined in Vue?

the file will generate vite ssr code, and exec in the vm. and the vm don't had load vite env. vite env inject the global vari when run in the serve or ssr mode.

@antfu
Copy link
Member

antfu commented Feb 13, 2022

Oh, interesting finding. But I guess importing /@vite/env once should be enough.
You can try to have await runner.executeId('/@vite/env') before:

for (const file of files)
await runner.executeFile(file)

@poyoho
Copy link
Member Author

poyoho commented Feb 13, 2022

oh, they only run in the difference worker, vm had the same context with worker 😂

@patak-dev patak-dev merged commit af9ceab into vitest-dev:main Feb 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for define global constants from vite.config
5 participants