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