英文:
How to auto import 'svelte/transition' with 'sveltekit-autoimport'?
问题
我尝试使用 sveltekit-autoimport 版本 1.6.10 自动导入 svelte/transition
模块。
在 vite.config.js
中
import { defineConfig } from 'vite'
import { svelte } from '@sveltejs/vite-plugin-svelte'
import autoImport from 'sveltekit-autoimport'
export default defineConfig({
plugins: [
autoImport({
components: ['./src/components'],
module: {
svelte: ['onMount', 'createEventDispatcher'],
'svelte/transition': ['fly'],
'svelte-apollo': ['mutation'],
},
}),
svelte()
]
})
一切都运作正常,除了:'svelte/transition': ['fly']
我也尝试了不同的组合和 mapping
替代 module
但无法使其工作。
autoImport({
mapping: {
fly: `import { fly } from 'svelte/transition'`
}
})
非常感谢任何帮助
英文:
I'm trying to use sveltekit-autoimport version 1.6.10 to auto import svelte/transition
module.
Inside vite.config.js
import { defineConfig } from 'vite'
import { svelte } from '@sveltejs/vite-plugin-svelte'
import autoImport from 'sveltekit-autoimport'
export default defineConfig({
plugins: [
autoImport({
components: ['./src/components'],
module: {
svelte: ['onMount', 'createEventDispatcher'],
'svelte/transition': ['fly'],
'svelte-apollo': ['mutation'],
},
}),
svelte()
]
})
Everything is working fine, except: 'svelte/transition': ['fly']
I also tried using different combinations and mapping
instead of module
but couldn't make it work.
autoImport({
mapping: {
fly: `import { fly } from 'svelte/transition'`
}
})
Any help will be really appreciated
答案1
得分: 0
您现在可以像以下方式一样无问题地使用它:
<script>
let visible = true
</script>
<label>
<input type="checkbox" bind:checked={visible}>
可见
</label>
{#if visible}
<p in:fly={{ y: 200 }} out:fly={{ y: 200 }}>
飞入和飞出
</p>
{/if}
不要忘记在vite.config.js
中的module
内首先添加它
autoImport({
module: {
'svelte/transition': ['fly']
}
})
英文:
This bug has been resolved in version 1.7.0
You can use it now without problems as follows:
<script>
let visible = true
</script>
<label>
<input type="checkbox" bind:checked={visible}>
visible
</label>
{#if visible}
<p in:fly={{ y: 200 }} out:fly={{ y: 200 }}>
Fly in and out
</p>
{/if}
Don't forget to add it first in module
inside vite.config.js
autoImport({
module: {
'svelte/transition': ['fly']
}
})
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论