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

Support matchImports in vueTemplateAddon #416

Open
1 task done
Sun79 opened this issue Jan 15, 2025 · 1 comment
Open
1 task done

Support matchImports in vueTemplateAddon #416

Sun79 opened this issue Jan 15, 2025 · 1 comment
Labels
enhancement New feature or request

Comments

@Sun79
Copy link
Contributor

Sun79 commented Jan 15, 2025

Background

When I use formily as a form library, rendering form controls involves the following approach:

<script setup lang="ts">
import { createForm } from '@formily/vue'
</script>

<template>
  <FormilyFormProvider :form="createForm()">
    <FormilyField
      name="input"
      title="input"
      :component="[FormilyInput]"
      :decorator="[FormilyFormItem]"
    />
    <FormilyField
      name="select"
      :component="[FormilySelect]"
      :data-source="[
        { value: 0, label: 'Female' },
        { value: 1, label: 'Male' },
      ]"
    />
  </FormilyFormProvider>
</template>

I want to automatically import components like FormilyInput, FormilyFormItem, and FormilySelect along with their styles. Currently, the resolvers configuration of unplugin-auto-import cannot achieve this because vueTemplateAddon does not support matchImports.

My Solution

To solve this issue, I came up with a solution, and the code can be found at https://github.com/Sun79/unimport/tree/feat/match-imports-in-vue-template.
I am not sure if this is the optimal solution, but it works well in my project.

Approach

In the transform hook, I only transform placeholders for Vue context properties that can match imports. Then, in the matchImports hook, I handle these placeholders and re-execute the matchImports hooks of other plugins to collect side effects.

Additional information

  • Would you be willing to help implement this feature?
@Sun79 Sun79 added the enhancement New feature or request label Jan 15, 2025
@Sun79
Copy link
Contributor Author

Sun79 commented Jan 15, 2025

Hi @antfu ,

Could you take a look at my solution and let me know if it’s feasible? The code is available here: https://github.com/Sun79/unimport/tree/feat/match-imports-in-vue-template.

Thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant