Nie*_*sma 5 svelte sapper svelte-3
使用以下代码:
<svelte:head>
<script type='application/ld+json'>
{
"@context": "https://schema.org",
"@type": "Organization",
"url": "https://filestar.com",
"logo": "https://filestar.com/logo-512.png"
}
</script>
</svelte:head>
Run Code Online (Sandbox Code Playgroud)
在获得:
[svelte-preprocess] Error transforming 'ld+json'.
Message:
Cannot find module './transformers/ld+json'
Stack:
Error: Cannot find module './transformers/ld+json'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
at Function.Module._load (internal/modules/cjs/loader.js:507:25)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Promise.resolve.then (C:\Repos\Filestar-Website\web-vnext\node_modules\svelte-preprocess\dist\utils.js:112:61)
Run Code Online (Sandbox Code Playgroud)
我已经尝试了这个 github 线程中的建议,结果相同:https : //github.com/sveltejs/svelte/issues/2438
对于登陆这里的任何人,Rich 的回答为您指明了正确的资源。
什么对我有用 Sapper:
// rollup.config.js
// ...
import sveltePreprocess from 'svelte-preprocess';
const preprocess = sveltePreprocess({
preserve: ['ld+json'],
// ...
});
export default {
client: {
plugins: [
svelte({
preprocess,
// ...
}),
},
server: {
plugins: [
svelte({
preprocess,
// ...
}),
],
},
};
Run Code Online (Sandbox Code Playgroud)
<!-- index.svelte -->
<script>
let jsonld = {
"@context": "http://schema.org",
"@type": "...",
"...": "..."
};
jsonld = JSON.stringify(jsonld);
</script>
<svelte:head>
{@html `<script type="application/ld+json">${jsonld}</script>`}
</svelte:head>
Run Code Online (Sandbox Code Playgroud)
附加说明:使用prettier和prettier-plugin-svelte,svelte 组件会发生不需要的更改。执行以下操作可以解决我的问题。
<!-- index.svelte -->
<script>
let jsonld = {
"@context": "http://schema.org",
"@type": "...",
"...": "..."
};
jsonld = JSON.stringify(jsonld);
let jsonldScript = `<script type="application/ld+json">${jsonld +
"<"}/script>`;
</script>
<svelte:head>
{@html jsonldScript}
</svelte:head>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
691 次 |
| 最近记录: |