ruoyi若依vue分离版前端资源打包到jar中

文章目录

前言

小项目,嫌麻烦,想用vue语法,但不想单独部署vue前端,希望把jar包放到服务器就行直接访问前端。


一、前端修改ruoyi-ui目录中vue.config.js

找到文件中module.exports对象中的outputDir值,修改为:

复制代码
outputDir: '../ruoyi-admin/src/main/resources/static',


二、后端修改

1、ruoyi-admin模块修改

1.1、修改pom

在build节点中加入以下代码

复制代码
<resources>
    <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
        <excludes>
            <exclude>static/**</exclude>
        </excludes>
    </resource>
    
    <resource>
        <directory>src/main/resources</directory>
        <filtering>false</filtering>
        <includes>
            <include>static/**</include>
        </includes>
    </resource>
</resources>

完整build配置,仅供参考

复制代码
<build>
     <plugins>
         <plugin>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-maven-plugin</artifactId>
             <version>2.5.15</version>
             <configuration>
                 <fork>true</fork> <!-- 如果没有该配置,devtools不会生效 -->
             </configuration>
             <executions>
                 <execution>
                     <goals>
                         <goal>repackage</goal>
                     </goals>
                 </execution>
             </executions>
         </plugin>
         <plugin>   
             <groupId>org.apache.maven.plugins</groupId>   
             <artifactId>maven-war-plugin</artifactId>   
             <version>3.1.0</version>   
             <configuration>
                 <failOnMissingWebXml>false</failOnMissingWebXml>
                 <warName>${project.artifactId}</warName>
             </configuration>   
        </plugin>   
     </plugins>
     <finalName>${project.artifactId}</finalName>
     
     <!--新加代码-->
	<resources>
         <resource>
             <directory>src/main/resources</directory>
             <filtering>true</filtering>
             <excludes>
                 <exclude>static/**</exclude>
             </excludes>
         </resource>
         
         <resource>
             <directory>src/main/resources</directory>
             <filtering>false</filtering>
             <includes>
                 <include>static/**</include>
             </includes>
         </resource>
     </resources>
</build>
1.2、修改SysIndexController

index()方法接口注释掉

2、ruoyi-framework模块修改

2.1、修改SecurityConfig配置开放resource/static的访问权限
复制代码
.antMatchers(HttpMethod.GET,"/static/**").permitAll()

三、前后端打包

1、执行前端打包

复制代码
npm run build:stage

或者

复制代码
npm run build:prod

前端打包完成后,资源文件已存放在后端ruoyi-admin模块resources/static目录中

2、后端正常打包即可

略过

四、访问验证

1、IP访问

复制代码
IP:PROT

2、域名访问

nginx server配置

复制代码
server {
	listen 80;
	server_name  你的域名;
	
    location / {
       	proxy_set_header Host $http_host;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header REMOTE-HOST $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_pass http://127.0.0.1:你的后端服务端口;
   }

    location /index {
        proxy_set_header Host $http_host;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header REMOTE-HOST $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_pass http://127.0.0.1:你的后端服务端口/;
   }

    location /prod-api/{
		proxy_set_header Host $http_host;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header REMOTE-HOST $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_pass http://127.0.0.1:你的后端服务端口/;
	}
	
    location /stage-api/{
		proxy_set_header Host $http_host;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header REMOTE-HOST $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_pass http://127.0.0.1:你的后端服务端口/;
	}
}

相关推荐
尘中客4 小时前
放弃 Echarts?前端直接渲染后端高精度 SVG 矢量图流的踩坑记录
前端·javascript·echarts·前端开发·svg矢量图·echarts避坑
FreeBuf_4 小时前
Chrome 0Day漏洞遭野外利用
前端·chrome
小彭努力中4 小时前
199.Vue3 + OpenLayers 实现:点击 / 拖动地图播放音频
前端·vue.js·音视频·openlayers·animate
2501_916007475 小时前
网站爬虫原理,基于浏览器点击行为还原可接口请求
前端·javascript·爬虫·ios·小程序·uni-app·iphone
前端大波5 小时前
Sentry 每日错误巡检自动化:设计思路与上手实战
前端·自动化·sentry
ZC跨境爬虫6 小时前
使用Claude Code开发校园交友平台前端UI全记录(含架构、坑点、登录逻辑及算法)
前端·ui·架构
慧一居士6 小时前
Vue项目中,何时使用布局、子组件嵌套、插槽 对应的使用场景,和完整的使用示例
前端·vue.js
Можно6 小时前
uni.request 和 axios 的区别?前端请求库全面对比
前端·uni-app
M ? A7 小时前
解决 VuReact 中 ESLint 规则冲突的完整指南
前端·react.js·前端框架
Jave21087 小时前
实现全局自定义loading指令
前端·vue.js