首先, 从前后端分离的角度来说, 不建议将编译后的vue工程放到SpringBoot工程目录下从而部署在Tomcat下, 因为这有点违背前后端分离的设计. 建议将其部署到Nginx下. 即分开部署后端代码与前端代码.
找到vue工程的 config/prod.env.js 文件(如果没有该文件可不处理), 修改 BASE_API 为正式环境后端服务API根地址:
'use strict' module.exports = { NODE_ENV: '"production"', BASE_API: '"http://localhost:8000"' }找到 config/index.js 文件, 修改 module.exports 下的build中的 assetsPublicPath 为 ‘/’:
/** * You can set by youself according to actual condition * You will need to set this if you plan to deploy your site under a sub path, * for example GitHub pages. If you plan to deploy your site to https://foo.github.io/bar/, * then assetsPublicPath should be set to "/bar/". * In most cases please use '/' !!! */ assetsPublicPath: '/',意即, 你设置为 ‘/’ , 表示编译后的静态文件要被部署到服务根路径下. 例如: 1.如果部署到Nginx, 映射到你Nginx的域名为 example.com 并且Nginx访问的根目录为文件夹A的话, 编译后的文件将会被部署到文件夹A路径下; 2.如果采用SpringBoot的话, 默认静态文件根路径为src/main/resource/static, 那么就需要将编译后的文件放在static下.
切换到Vue工程根目录, 例如:
cd eladmin-qd执行npm编译
npm run build这样之后就会在工程根目录生成一个dist文件夹, 编译好的静态文件就在这里面:
将这个三个文件拷贝到SpringBoot工程的static文件夹下: 这样子之后打包的工程运行后可通过 域名或ip 访问: