Skip to content
This repository has been archived by the owner on Feb 26, 2023. It is now read-only.

Research on auto-import feature feasibility #533

Open
pournasserian opened this issue Sep 29, 2022 · 4 comments
Open

Research on auto-import feature feasibility #533

pournasserian opened this issue Sep 29, 2022 · 4 comments
Assignees
Labels
enhancement New feature or request question Further information is requested

Comments

@pournasserian pournasserian added enhancement New feature or request question Further information is requested labels Sep 29, 2022
@TheHadiAhmadi
Copy link
Collaborator

TheHadiAhmadi commented Sep 29, 2022

@pournasserian It is easy to use and We don't have problems with typescript, I added sveltekit-autoimport package in https://github.com/ubeac/ui-template repo here.
sveltekit-autoimport is a vite plugin and works similar to a preprocessor, and only imports components that we used in our code.

@TheHadiAhmadi
Copy link
Collaborator

@pournasserian @mhmdtaherian please review https://github.com/ubeac/ui-template/pull/2 and see if does it worth using auto-import or not?

reduces at least 2 lines of code from each page file.

@TheHadiAhmadi
Copy link
Collaborator

TheHadiAhmadi commented Sep 29, 2022

we need to move this file here (ubeac/svelte) repo and add all other components.

also I have a suggestion, we can create a vite plugin to enable/disable autoImport, ifProcessor, eachProcessor, previewProcessor and more...

import { sveltekit } from '@sveltejs/kit/vite';
import type { UserConfig } from 'vite';

import ifProcessor from '@ubeac/svelte/preprocessors/if.js'
import eachProcessor from '@ubeac/svelte/preprocessors/each.js'

import autoImport from 'sveltekit-autoimport';

const config: UserConfig = {
  plugins: [
    autoImport({
      components: ['./src/components/page', '@ubeac/svelte/components'],
    }),
    ifProcessor(),
    eachProcessor(),
    sveltekit(),
  ]
};

export default config;

After:

import ubeac from '@ubeac/svelte/vite';
import type { UserConfig } from 'vite';

const config: UserConfig = {
  plugins: [
    ubeac({
      autoImport: { 
        components: [
          './src/components/page', // '@ubeac/svelte/components' should be enabled by default 
        ] 
      },
      if: true, // default is true
      each: false // we can also disable some of these features
    })
  ]
};

export default config;

@TheHadiAhmadi
Copy link
Collaborator

Also there is another package called unplugin-auto-import which can also generate .d.ts files, but it doesn't work in .svelte files. We can use both of these packages to have auto generated .d.ts file and have benefits of sveltekit-autoimport.

I updated the PR https://github.com/ubeac/ui-template/pull/2 and now it should support all @ubeac/svelte components

one problem of using auto-import feature is that if we have custom component in our local repo, the component which comes from @ubeac/svelte is prefered.

for example we have Page component in @ubeac/svelte, and also in src/components/page/Page.svelte, we need to disable the component from @ubeac/svelte and register our custom src/components/page/Page.svelte component

(we can have an excluded option for ubeac plugin)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request question Further information is requested
Projects
Status: No status
Development

No branches or pull requests

2 participants