Vue + SpringBoot 發(fā)布項目

1). 打包Vue項目
  • 修改配置
    /config/目錄下的index.js打開修改,將build中assetsPublicPath屬性修改為'./'
  build: {
    // Template for index.html
    index: path.resolve(__dirname, '../dist/index.html'),

    // Paths
    assetsRoot: path.resolve(__dirname, '../dist'),
    assetsSubDirectory: 'static',
    assetsPublicPath: './',
  }
圖1.png
  • 打包
    在項目的根目錄下執(zhí)行npm run build,執(zhí)行成功后,在dist文件夾生成static文件夾和index.html文件
    圖2.png
2). 創(chuàng)建文件夾

在SpringBoot項目中,并將第1步中dist文件夾中的內容全部拷貝到/src/main/resources/static/文件夾下

圖3.png

3). 配置application.yml

配置prefix,suffix和static-locations

# spring 配置
spring:
  mvc:
    view:
      # 如果配置了spring-resources,則必須包含classpath:/static/
      # 訪問靜態(tài)頁面 /pages/指定路徑為 /static/pages/
      prefix: /
      # 靜態(tài)頁面后綴
      suffix: .html
  resources:
    # 靜態(tài)文件路徑, 資源路徑,博客路徑
    static-locations: classpath:/static/, classpath:/blog/
4). Controller配置
@Controller
class HomeController {
    /**
     * 訪問首頁方式
     * 切記不能配置index.html
     */
    @GetMapping("/", "/index")
    fun index() : String{
        return "index"
    }
}
5). 運行項目
6). 瀏覽器訪問http://localhost:8080/即可現實index.html內容
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容