如何将 svelte-preprocess 的结果发送到文件中
how to send the result of svelte-preprocess into a file
是否可以(如果可以,如何)将 svelte-preprocess
运行 的结果保存到外部文件中?
我的动机:我使用 TypeScript 编写了一个 Svelte 组件 - 但是将我的 package.json
的 svelte
字段指向原始(即 TypeScript)源允许非 TypeScript-savvy 环境(例如 Svelte REPL)因语法错误而失败。
因此,我需要发布我的原始组件的转译版本——没有任何捆绑(允许 Svelte 优化其最终捆绑)
[编辑] 下面显示的已接受答案促使我编写了一个实际解决上述问题的 Svelte 预处理器。如果其他人遇到过类似情况:看看 save-to-file
你可以自己创建一个预处理器,然后用生成的代码做你想做的事
确保在 sveltePreprocess
之后包含预处理器以获取编译后的代码
plugins: [
svelte({
preprocess: [
sveltePreprocess({sourceMap: !production}),
{
script: ({attributes, content, filename, markup}) => {
console.log({content, filename});
},
markup: ({content, filename}) => {
console.log({content, filename});
},
style: ({attributes, content, filename, markup}) => {
console.log({content, filename});
}
}
],
}),
你可以创建一种地图,assemble 编译组件,因为你有脚本、标记和样式
是否可以(如果可以,如何)将 svelte-preprocess
运行 的结果保存到外部文件中?
我的动机:我使用 TypeScript 编写了一个 Svelte 组件 - 但是将我的 package.json
的 svelte
字段指向原始(即 TypeScript)源允许非 TypeScript-savvy 环境(例如 Svelte REPL)因语法错误而失败。
因此,我需要发布我的原始组件的转译版本——没有任何捆绑(允许 Svelte 优化其最终捆绑)
[编辑] 下面显示的已接受答案促使我编写了一个实际解决上述问题的 Svelte 预处理器。如果其他人遇到过类似情况:看看 save-to-file
你可以自己创建一个预处理器,然后用生成的代码做你想做的事
确保在 sveltePreprocess
之后包含预处理器以获取编译后的代码
plugins: [
svelte({
preprocess: [
sveltePreprocess({sourceMap: !production}),
{
script: ({attributes, content, filename, markup}) => {
console.log({content, filename});
},
markup: ({content, filename}) => {
console.log({content, filename});
},
style: ({attributes, content, filename, markup}) => {
console.log({content, filename});
}
}
],
}),
你可以创建一种地图,assemble 编译组件,因为你有脚本、标记和样式