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

feat(plugin-vue): enhancements #984

Merged
merged 5 commits into from
Sep 9, 2020

Conversation

Akimyou
Copy link
Contributor

@Akimyou Akimyou commented Sep 2, 2020

Changes

  • 1. Full support script lang ts in vue file
    • plugin option: tsconfig
  • 2. Portion support script lang ts in vue file and tsx, jsx file
    • Testing Demo Repo
    • Project template app-template-vue-typescript
  • 3. Fix vue css hmr bug

1. Full support script lang ts in vue file

// example.vue

<template>
  <div class="app">
    <Layout>
      <router-view></router-view>
    </Layout>
  </div>
</template>

<script lang="ts">
import { defineComponent, reactive, computed } from 'vue'
import Layout from '/@/components/Layout.vue'

export default defineComponent({
  name: 'App',
  components: {
    Layout,
  },
})
</script>

Use esbuild compile script content ts code to js code. ✌️ As vite, we can't support type check in compile time.

https://github.com/pikapkg/snowpack/pull/984/files#diff-460291335ddc08075bf891e8e0c5f93fR64

2. Portion support script lang ts in vue file and tsx, jsx file

Use esbuild jsxFactory compile script tsx, jsx content and tsx, jsx files.

https://github.com/pikapkg/snowpack/pull/984/files#diff-460291335ddc08075bf891e8e0c5f93fR63

If need to use tsx and jsx files, need the config plugins/plugin-vue/plugin-tsx-jsx.js.

https://github.com/pikapkg/snowpack/pull/984/files#diff-460291335ddc08075bf891e8e0c5f93fR63

Limitation

May be have some limitation compare to: https://github.com/vuejs/jsx-next/tree/dev/packages/babel-plugin-jsx, such as un support vue directive v-for, v-if, v-model and so on.

But we use the same way to resolve tsx, jsx code as vite, so vite have the same limitation.

https://github.com/vitejs/vite/blob/master/src/node/esbuildService.ts#L77

Should we need to support option to use babel compile and babel-plugin-jsx ? Need U suggestion.

3. Fix vue css hmr bug

For support style hmr update in vue file. The wrapResponse must be in frontend of resolveResponseImports

https://github.com/pikapkg/snowpack/pull/984/files#diff-7101fc032cd14c955a7f47f91a7f7245R639

Project template app-template-vue-typescript

New PR after this feature released.

Testing

Added: plugins/plugin-vue/test.

How to manage the plugin test cases ? Need U suggestion.

Testing Demo Repo

Please try on: https://github.com/Akimyou/snowpack/tree/feature/plugin-vue-enhance-demo/create-snowpack-app/app-template-vue-typescript

@Akimyou Akimyou requested a review from a team as a code owner September 2, 2020 10:38
@vercel vercel bot temporarily deployed to Preview September 2, 2020 10:38 Inactive
@vercel
Copy link

vercel bot commented Sep 2, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/pikapkg/snowpack/cxwhtksea
✅ Preview: Canceled

[update for 0acf94e canceled]

@Akimyou Akimyou changed the title feat plugin-vue-enhance WIP:feat plugin-vue-enhance Sep 2, 2020
@Akimyou Akimyou changed the title WIP:feat plugin-vue-enhance WIP: feat plugin-vue-enhance Sep 2, 2020
@FredKSchott
Copy link
Owner

This makes sense to me, and seems to be a really valuable feature. would love to see this work finished and merged!

@Akimyou Akimyou force-pushed the feature/plugin-vue-enhance branch from c9f1f26 to a195711 Compare September 3, 2020 05:51
@vercel vercel bot temporarily deployed to Preview September 3, 2020 05:51 Inactive
@Akimyou Akimyou force-pushed the feature/plugin-vue-enhance branch from a195711 to 30d3050 Compare September 3, 2020 08:28
@vercel vercel bot temporarily deployed to Preview September 3, 2020 08:28 Inactive
@Akimyou Akimyou force-pushed the feature/plugin-vue-enhance branch from 30d3050 to 1861a54 Compare September 3, 2020 10:26
@vercel vercel bot temporarily deployed to Preview September 3, 2020 10:26 Inactive
@Akimyou Akimyou force-pushed the feature/plugin-vue-enhance branch from 1861a54 to 92c66ae Compare September 3, 2020 10:51
@vercel vercel bot temporarily deployed to Preview September 3, 2020 10:51 Inactive
@Akimyou Akimyou force-pushed the feature/plugin-vue-enhance branch from 92c66ae to 3824090 Compare September 3, 2020 10:54
@vercel vercel bot temporarily deployed to Preview September 3, 2020 10:54 Inactive
@Akimyou Akimyou force-pushed the feature/plugin-vue-enhance branch from 3824090 to 88eefad Compare September 3, 2020 13:49
@vercel vercel bot temporarily deployed to Preview September 3, 2020 13:49 Inactive
@vercel vercel bot temporarily deployed to Preview September 3, 2020 15:33 Inactive
@Akimyou Akimyou changed the title WIP: feat plugin-vue-enhance feat plugin-vue-enhance Sep 3, 2020
@Akimyou
Copy link
Contributor Author

Akimyou commented Sep 3, 2020

@FredKSchott , finished. Need U review.

@vercel vercel bot temporarily deployed to Preview September 4, 2020 02:28 Inactive
@FredKSchott
Copy link
Owner

Should we need to support option to use babel compile and babel-plugin-jsx ? Need U suggestion.

Just confirming: are these limitations new, or do they currently exist in the plugin? I'm fine to merge as long as it is not a new regression that could knowingly break existing users. Otherwise, we can wait until a user reports running into this limitation before resolving it.

How to manage the plugin test cases ? Need U suggestion.

@gr2m is working on improving our tests for plugins, I'll let him answer/review this aspect of the PR.

Copy link
Owner

@FredKSchott FredKSchott left a comment

Choose a reason for hiding this comment

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

Looks good! Left a couple of comments, and then would love @gr2m to review tests before merging.

plugins/plugin-vue/src/script-compilers.js Show resolved Hide resolved
@vercel vercel bot temporarily deployed to Preview September 7, 2020 02:32 Inactive
@Akimyou
Copy link
Contributor Author

Akimyou commented Sep 7, 2020

Just confirming: are these limitations new, or do they currently exist in the plugin? I'm fine to merge as long as it is not a new regression that could knowingly break existing users. Otherwise, we can wait until a user reports running into this limitation before resolving it.

These limitations are not exist in the plugin, because current plugin do not support jsx/tsx feature. So the limitations come with our new feature that will not break existing users. We can wait until a user reports running into this limitation before resolving it. (Agree with it)

About the License

Thank you for tell me the License problem, I understand with it.
So I add Vite License here.

https://github.com/pikapkg/snowpack/pull/984/files#diff-52e9f81ed066f12a83aa4401fbbdddf7R1

About the tests

according to : evanw/esbuild#366
I del the option: tsconfig. Because esbuild.transform api do not support config through tsconfig file. I del related test too.

Copy link
Owner

@FredKSchott FredKSchott left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for the thorough tests as well!

@FredKSchott
Copy link
Owner

/cc @gr2m to take another look before merging, since he brought up the original testing questions. (Also, I'm +1 for bringing this plugin testing style to the rest of our plugins, since it seems like Jest just automatically runs these without any new config).

Copy link
Contributor

@gr2m gr2m left a comment

Choose a reason for hiding this comment

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

Tests look great! I agree that it would be fantastic to do similar tests for other plugins. I'll give it a try myself, and then start a follow up discussion so others can contribute

@gr2m gr2m changed the title feat plugin-vue-enhance feat(plugin-vue): enhancements Sep 8, 2020
@gr2m
Copy link
Contributor

gr2m commented Sep 8, 2020

Would you prefer to add app-template-vue-typescript as part of this pull request, or make a follow up pull request for it? I'd prefer the latter if you don't mind

@Akimyou
Copy link
Contributor Author

Akimyou commented Sep 9, 2020

Would you prefer to add app-template-vue-typescript as part of this pull request, or make a follow up pull request for it? I'd prefer the latter if you don't mind

I prefer the latter. Because current app-template project always deps on an released plugin. https://github.com/pikapkg/snowpack/blob/master/create-snowpack-app/app-template-vue/package.json#L20

@gr2m gr2m merged commit 0c5390d into FredKSchott:master Sep 9, 2020
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.

3 participants