在特定业务场景下,打包后部署的外部访问路径并不是根路径或者需要加一个特定的访问前缀,这时候就需要打包后的资源引用使用相对路径,具体解决方法, 编辑项目里面的 .aid/aid.js
文件
- 配置代码拆分懒加载的引用前缀
beforeBuild() {
return {
publicPath: ''
}
}
- 配置构建后的index.html中js,css等资源的引用前缀
outputPrefix: ''
- 配置不参与构建的static资源引用前缀
staticPrefix(staticFolder, file) {
if (extname(file) === '.css') {
return '../static'
}
return 'static'
}
- 修改工程内
vue-router
的配置
const router = new VueRouter({
base: '<访问前缀>',
})
- 服务器部署的配置,请参见 vue-router后端配置
nginx示例
location ^~ /<访问前缀> {
alias /path/to/project;
index index.html;
try_files $uri $uri/ /index.html =404;
}