vite-plugin-vue icon indicating copy to clipboard operation
vite-plugin-vue copied to clipboard

feat: support pre-bundle

Open aa900031 opened this issue 2 years ago • 5 comments

Description

As mentioned in this https://github.com/vitejs/vite/issues/3910, external files (.vue) not pre-bundle in Vite. According to the discussion thread, it has been confirmed that Svelte already supports this feature. So, here we will implement the same approach to enable Vite Pre-bundling for Vue SFC.

I believe this feature would be very helpful for Vue SFC library development. With the help of https://github.com/unjs/mkdist, we can perform transform and directly publish it to npm. When developers who use this library want to deploy their websites, they can rely on the installed @vue/compiler-sfc to compile the SFCs within the library.


What is the purpose of this pull request?

  • [ ] Bug fix
  • [x] 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 Commit 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.

aa900031 avatar Jun 14 '23 17:06 aa900031

@sxzz Please check this PR, Welcome to discussion. Thank you.

aa900031 avatar Aug 25 '23 05:08 aa900031

Hi @sxzz! Thank you for the review. I've resolved all the comments. Please check it again

aa900031 avatar Aug 25 '23 17:08 aa900031

Try to run cd ./playground/vue-sfc-prebundle && pnpm vite optimize --force && pnpm dev and there's an error.

Uncaught TypeError: Cannot read properties of undefined (reading '__vccOpts')
    at plugin_vue_export_helper_default (@vitejs_test-lib-component.js?v=574ab827:9:22)
    at @vitejs_test-lib-component.js?v=574ab827:58:21

sxzz avatar Aug 26 '23 03:08 sxzz

@sxzz I have same error now, but after reverting to the code before the merge f85e9c61832e9e5fb7c8784b55af2a9b140bcecb, everything is back to normal.

This is quite unusual. I should spend more time confirming where the issue might be.

aa900031 avatar Aug 26 '23 09:08 aa900031

@sxzz I've discovered the prebundle is not handling TypeScript-related content (hence the errors when importing CompC.vue and CompD.vue). So, I'm making theprebundle transforms consistent with the original transforms.

aa900031 avatar Aug 27 '23 17:08 aa900031

Closing this due to stale. Additionally, Vite will use Rolldown for bundling instead of esbuild plugins in the future.

sxzz avatar May 30 '24 18:05 sxzz