如何在使用适配器节点构建的非根路径上部署 sveltekit 应用程序?

编程入门 行业动态 更新时间:2024-10-05 15:29:24

如何在使用<a href=https://www.elefans.com/category/jswz/34/1764610.html style=适配器节点构建的非根路径上部署 sveltekit 应用程序?"/>

如何在使用适配器节点构建的非根路径上部署 sveltekit 应用程序?

我创建了一个 Sveltekit 应用程序,我想将其托管在非根路径,例如 http://localhost:3000/dashboard

我的

svelte.config.js

import adapter from '@sveltejs/adapter-node';
import preprocess from "svelte-preprocess";

/** @type {import('@sveltejs/kit').Config} */
const config = {
    kit: {
        adapter: adapter(),
        paths: {
            base: '/dashboard',
        },
        csrf: { checkOrigin: false }
    },
    preprocess: [
        preprocess({
            scss: {
                prependData: '@use "src/variables.scss" as *;',
            },
        }),
    ],
    output: {
        globalObject: 'this',
    },
};

export default config;

我正在使用像

<img src="/images/logo_new.svg">

这样的图像

我可以使用命令构建

npm run build

要运行,我正在使用命令

node build

现在我可以在 http://localhost:3000/dashboard 上看到我的应用程序,但无法加载图像。在控制台中,我看到所有图像路径都是 404。

我的应用程序试图打开 http://localhost:3000/images/logo_new.svg 而不是 http://localhost:3000/dashboard/images/logo_new.svg

在非根路径上部署 sveltekit 应用程序的正确方法是什么?

回答如下:

更多推荐

如何在使用适配器节点构建的非根路径上部署 sveltekit 应用程序?

本文发布于:2024-05-30 08:08:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1770284.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:适配器   节点   应用程序   路径   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!