Vue项目使用Nginx部署并发布到子目录 默认Vue项目是以根目录来发布的,但是我们要有时候希望以子目录来做发布,那么就需要做一些修改,Vue项目本身的配置,包括Nginx也需要做一些配置修改。 对Vue项目源码的修改 以下路径以vue-cli常见项目的文件结构来说明。 修改路由:router/index.js,添加base部分的代码。 1 2 3 4 5 6 7 8 9 10 function getAbsolutePath () { let path = location.pathname return path.substring(0, path.lastIndexOf('/') + 1) } export default new Router({ mode: 'hash', base: getAbsolutePath(), routes: [...] }) 修改配置:config/index.js 文件,对于打包路径的定义,只处理build,将assetsPublicPath: '/'修改为assetsPublicPath: './' 1 2 3 4 5 6 7 8 9 10 11 12 module.exports = { build: { // Template for index.html index: path.resolve(__dirname, '../dist/index.html'), // Paths assetsRoot: path.……

阅读全文