我正在尝试重写用 pugjs 制作的应用程序并用 sveltejs 表达。我真的很喜欢在 pugjs 中写 html。我想知道是否可以在 svelte 组件中使用 pugjs。我假设我可能需要使用苗条装载机 https://github.com/sveltejs/svelte-loader并进行一些预处理,或者这甚至可能吗?我在用着Sapper https://github.com/sveltejs/sapper以 svelte 重写我的应用程序。谁能帮我在 Sapper 中如何做到这一点?
有一个带有烘焙功能的 Svelte 预处理器包装器,支持常用的预处理器,包括 Pug:https://github.com/kaisermann/svelte-preprocess https://github.com/kaisermann/svelte-preprocess
这是我的哈巴狗混音,包括奖金show
mixin(如 Vue 的v-show
)。
在底部,您可以看到如何将它们与 svelte-preprocess 集成。
const pugMixins = `
mixin if(condition)
| {#if !{condition}}
block
| {/if}
mixin else
| {:else}
block
mixin elseif(condition)
| {:elseif !{condition}}
block
mixin each(loop)
| {#each !{loop}}
block
| {/each}
mixin await(promise)
| {#await !{promise}}
block
| {/await}
mixin then(answer)
| {:then !{answer}}
block
mixin catch(error)
| {:catch !{error}}
block
mixin debug(variables)
| {@debug !{variables}}
mixin show(condition)
div(style!="display: {" + condition + " ? 'initial' : 'none'}")
block
`
export default {
/** Transform the whole markup before preprocessing */
onBefore({ content, filename }) {
return content.replace('<template lang="pug">', '<template lang="pug">' + pugMixins)
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)