如何将标题添加到使用 svelte 模板在 codesandbox 中创建的沙箱

How to add a title to a sandbox created in codesandbox with the svelte template

我使用 svelte 客户端模板在 codesandbox 中创建了一个 svelte 项目。当我在它自己的 window 中打开沙箱的输出时,标题是 "Sandbox - CodeSandbox".

默认模板使用汇总,但是它在 sandbox.config.json 文件的顶部说它不会在沙盒中影响它,这似乎是正确的。没有现有的 index.html 文件可以编辑它。

https://codesandbox.io/s/transformer-svelte-ghtyd?fontsize=14&module=%2FApp.svelte

您可以在项目的根级别创建一个 public 目录,并在其中添加一个 index.html 文件。只需确保包含您的构建将生成的 JS 和 CSS 包。

您还可以使用 degit - 一种脚手架工具 - 从模板项目开始,如 here 所述。这将为您生成 public 目录和 index.html 文件等。

模板真的很简单(在我看来是件好事)。自己看看:

<!doctype html>
<html>
<head>
    <meta charset='utf-8'>
    <meta name='viewport' content='width=device-width'>

    <title>Svelte app</title>

    <link rel='icon' type='image/png' href='/favicon.png'>
    <link rel='stylesheet' href='/global.css'>
    <link rel='stylesheet' href='/bundle.css'>

    <script defer src='/bundle.js'></script>
</head>

<body>
</body>
</html>