javascript - 从文件 ://with no sever 运行 Svelte 应用程序

标签 javascript svelte svelte-3

我需要运行一个 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 应用程序中,您可以在没有运行服务器的情况下执行此操作。

请参照附件

screenshot

您将获得 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/

相关文章:

javascript - 为什么 d3.json 返回 "null"?

svelte - Svelte 如何处理在 each 循环中更新数组中的对象

javascript - 如何根据 Svelte 中的 props 设置动态 html 标签

javascript - 在回调中访问 Svelte 组件属性?

javascript - 如何在 Sapper 中离开父布局?

javascript - 在 JSON 数组中搜索字符串并检索包含该字符串作为值的对象

javascript - 如何只为 firefox 加载脚本

javascript - 在 jquery 中追加一个元素

ag-grid - 如何使用需要绑定(bind)到 DOM 节点的 JavaScript 库

javascript - Sapper 在点击链接时不会重新加载数据