vite-plugin-vue
vite-plugin-vue copied to clipboard
fix(plugin-vue): hmr got error by transformSFC to inject code (fix #301)
Description
FIXED: #301
Some vite plugins like unocss:vue-scoped needs to rewrite hmrContext.read to inject their special code into SFC when hmr.
vite-plugin-vue uses fs.readFileSync to get the raw code, but the raw code doesn't have injected code by other plugins.
This PR allows vite-plugin-vue to get transformCode api from other plugins, and then replace fs.readFileSync with readCode function.
Additional context
- hmr error reproduction: https://stackblitz.com/edit/vitejs-vite-28qyca?file=src%2FApp.vue
- Wait to start and change class
text-bluetotext-red
- Wait to start and change class
- playground for this PR: https://stackblitz.com/edit/vitejs-vite-6tuitn?file=src%2FApp.vue
- u can run it locally
What is the purpose of this pull request?
- [X] Bug fix
- [ ] New Feature
- [ ] Documentation update
- [ ] Other
Before submitting the PR, please make sure you do the following
- [x] Read the Contributing Guidelines.
- [x] Read the Pull Request Guidelines and follow the PR Title Convention.
- [x] Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
- [x] Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g.
fixes #123). - [x] Ideally, include relevant tests that fail without this PR but pass with it.