SpringBoot+Vue项目打jar包


 一、打包Vue项目(开发工具webStorm)

vue搭建脚手架报错:rollbackFailedOptinal:verb npm-session

建议使用外网,不要用公司内网

添加依赖:npm install

进行打包:npm run build

之后会出现dist文件夹

将dist下的文件放到idea中的static下

添加静态资源访问的配置和依赖

<!--导入配置文件处理器,配置文件进行绑定就会有提示-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>

package com.answer.testvue.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath/static/**").resourceChain(true);
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {

        registry.addViewController("/").setViewName("forward:/index.html");


    }
}

因为我的spring boot是个空的项目,没有数据库连接什么的,所以需要跳过数据库自动配置

同时也需要关闭这个,点击闪电按钮,这是为了防止之后打包失败

之后install打包,然后在target下找到打好的jar包并启动

 

启动成功

参考链接:webStorm打包vue项目并且部署到服务器_滑稽的鼠标的博客-CSDN博客_webstorm打包vue项目

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM