方法一
生产环境打包到子目录
module.exports = {
publicPath: process.env.NODE_ENV === 'production' ? '/test/' : '/',
outputDir: 'dist/test',
assetsDir: 'static',
}
路由增加根目录
在vue-router配置中增加base属性,声明路由根目录
export default new Router({
base: process.env.BASE_URL,
...
})
nginx 配置子目录路径
由于路由使用了HTML5 History模式,所以需要进行特殊的配置
如果是直接部署在根目录,配置如下
location /test {
root E:/xx/dist;
index index.html index.htm;
try_files $uri $uri/ /test/index.html;
}
方法二
生产环境打包到子目录
module.exports = {
publicPath: '/test/',
outputDir: 'test',
assetsDir: 'static',
}
路由增加根目录
在vue-router配置中增加base属性,声明路由根目录
export default new Router({
base: '/test/',
...
})
nginx 配置子目录路径
由于路由使用了HTML5 History模式,所以需要进行特殊的配置
如果是直接部署在根目录,配置如下
location /test {
root E:/xx/ test外层文件夹名;
index index.html index.htm;
try_files $uri $uri/ /test/index.html;
}