【发布时间】:2019-08-29 14:34:43
【问题描述】:
我正在使用@vue/cli / vue version 3.5.5 制作一个简单的 2 页网站。
到目前为止一切顺利,当我使用 npm run serve 在本地运行网站,然后使用 npm run build 创建我的 dist/ 文件夹时。
当我将 dist/ 文件夹中的文件添加到主机的根目录并访问 http://www.my-website.com 上的生产环境时,页面呈现并正常运行。
但是,我想将应用程序托管在子目录中,但这会弄乱路由,因为 index.html 不会呈现。
访问 http://www.my-website.com/dist 时:index.html 返回空白并在控制台中显示错误消息:
app.a1183de6.js:1 Failed to load resource: the server responded with a status of 404 (Not Found)
chunk-vendors.ff22d1fb.js:1 Failed to load resource: the server responded with a status of 404 (Not Found)
about.ad763791.js:1 Failed to load resource: the server responded with a status of 404 (Not Found)
app.a1183de6.js:1 Failed to load resource: the server responded with a status of 404 (Not Found)
提供背景,包括您已经尝试过的内容
我花了好几个小时搜索,最常见的是创建一个vue.config.js 文件并将根路径改为子目录
module.exports = {
baseUrl: process.env.NODE_ENV === 'production'
? '/dist/'
: '/'
}
我也试过了,但是不行:
// module.exports = {
// publicPath:' /dist/ '
// }
我按照指示将vue.config.js 文件放在项目文件夹的根目录下,但它似乎在npm run build 上被忽略了
描述预期和实际结果:
我想在子目录中渲染我的 vue-app,例如:
http://www.website.com/dist
但是现在,当我在子目录中托管我的项目时,我在控制台中得到一个空白的 index.html 页面和错误消息。如果我将它托管在根目录中,该项目运行良好
【问题讨论】:
标签: vue.js build vue-cli vue-cli-3