配置 nuxt.js 应用程序以在网络服务器上的子目录中工作 [英] Configure nuxt.js application to work in a subdirectory on a webserver

查看:35
本文介绍了配置 nuxt.js 应用程序以在网络服务器上的子目录中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将静态 nuxt.js 应用程序(使用 nuxt generate 构建)部署到网络服务器的子目录.nuxt默认将生成的文件放在dist目录下:

I want to deploy a static nuxt.js application (built with nuxt generate) to a subdirectory of a webserver. nuxt places the generated files in the dist directory by default:

如果我在 dist 文件夹的 父目录 上启动网络服务器并使用以下命令打开页面:

If I start a webserver on the parent directory of the dist folder and open the page with:

http://localhost:34360/dist/

站点无法从域根目录加载脚本文件:

the site fails to load the script files from the domain root directory:

我尝试在 nuxt 配置中设置 publicPath 属性:

I've tried setting the publicPath property in the nuxt config:

build: {
  publicPath: '/dist/'
}

应用程序编译为:

现在,nuxt 将脚本文件向下移动一级(/dist/dist)并再次搜索根级别(/dist),因此仍然找不到文件

Now, nuxt moves the script files one level lower (/dist/dist) and searches on root level again (/dist), thus still not finding the files

如何配置站点,以便加载脚本和资产并且它是自包含的,无论我将它放在服务器上的哪个目录中?

该问题已在 在 GitHub 上 涵盖,但建议的提示(使用 publicPath) 不起作用,如上所示.

The issue has been covered on GitHub but the suggested hints (using publicPath) didn't work, as shown above.

旁注:我不想指定 publicPath absolut(即 http://localhost:8080/dist),这会起作用但会产生新问题.

Sidenote: I do not want to specify the publicPath absolut (i.e. http://localhost:8080/dist), which would work but creates new problems.

推荐答案

你需要 router/base

router: {
  base: '/dist/'
}

这篇关于配置 nuxt.js 应用程序以在网络服务器上的子目录中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆