vue打包整合到springboot

vue-cli打包整合到springboot遇到的问题

第一种情况

vue.config.js配置

注意 publicPath改为dist ,3之前对应的是assetsPublicPath

const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
	publicPath: process.env.NODE_ENV === 'production' ? '/dist/' : './',
	//outputDir :'dist',/*默认dist*/
	assetsDir:'static',
  transpileDependencies: true
})

springboot下yml简单配置如下

server:
  port: 8001

然后 npm run build 把打包后的文件丢到resource下static目录下

在这里插入图片描述

在浏览器访问

http://127.0.0.1:8001/dist/index.html

效果如下
在这里插入图片描述

若不想用dist前缀

只需修改vue.config.js

const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
	publicPath: process.env.NODE_ENV === 'production' ? '/cool/' : './',
	outputDir :'cool',/*默认dist*/
	assetsDir:'static',
  transpileDependencies: true
})

访问 http://127.0.0.1:8001/cool/index.html
在这里插入图片描述

如果springboot下配置了 servlet.context-path

application.yml简单配置如下

server:
  port: 8001
  servlet.context-path: /test

目录结构

修改vue.config.js

const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
	publicPath: process.env.NODE_ENV === 'production' ? '/test/cool/' : './',
	outputDir :'cool',/*默认dist*/
	assetsDir:'static',
  transpileDependencies: true
})

则访问地址变为
http://127.0.0.1:8001/test/cool/index.html

在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值