最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

网站源码admin48浏览0评论

如何在使用适配器节点构建的非根路径上部署 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 应用程序的正确方法是什么?

回答如下:
发布评论

评论列表(0)

  1. 暂无评论