我需要运行一个 Svelte 应用程序并且能够在没有服务器的情况下执行它。
对于其他框架,这是可能的,因为它只是 javascript,但我找不到一种方法来单击我的 index.html 并运行我用 Svelte 构建的应用程序
最佳答案
I need to run a Svelte app and be able to execute it without a server. With other frameworks this is possible as it is just javascript but I can't find a way to just click my index.html and run my app built with Svelte
我将把它分解为两个组件,构建和执行纤细的应用程序。
首先,你需要一台电脑来
build
Svelte 应用程序在执行汇总(并运行节点服务器)以执行编译时,但这不是 OP 所要求的......解决
execution
在 Svelte 应用程序中,您可以在没有运行服务器的情况下执行此操作。请参照附件
您将获得
npm run build
从 Svelte create-svelte app generate 命令输出 public.html
.这可以用来在 Surge.sh 上托管文件,但是为了使这个“本地文件友好”,您需要将输出的 html 编辑为以下内容(即删除基础
/
)。原始来源 index.html
<link rel='icon' type='image/png' href='/favicon.png'>
<link rel='stylesheet' href='global.css'>
<link rel='stylesheet' href='/build/bundle.css'>
<script defer src='/build/bundle.js'></script>
最终的 html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width,initial-scale=1'>
<title>Svelte app</title>
<link rel='icon' type='image/png' href='favicon.png'>
<link rel='stylesheet' href='global.css'>
<link rel='stylesheet' href='build/bundle.css'>
<script defer src='build/bundle.js'></script>
</head>
<body>
</body>
</html>
关于javascript - 从文件 ://with no sever 运行 Svelte 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61966179/