All Projects → tokuhirom → Spring Vue Sample

tokuhirom / Spring Vue Sample

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Spring Vue Sample

Ng Boot Oauth
oauth2 demo with angularjs and springboot
Stars: ✭ 99 (+43.48%)
Mutual labels:  webpack, spring-boot
Jhipster4 Demo
Blog demo app with JHipster 4
Stars: ✭ 180 (+160.87%)
Mutual labels:  webpack, spring-boot
Jhipster Microservices Example
JHipster Microservices Example using Spring Cloud, Spring Boot, Angular, Docker, and Kubernetes
Stars: ✭ 100 (+44.93%)
Mutual labels:  webpack, spring-boot
Spring Boot Vuejs
Example project showing how to build a Spring Boot App providing a GUI with Vue.js
Stars: ✭ 1,818 (+2534.78%)
Mutual labels:  webpack, spring-boot
Spring Streaming
SPA on Spring Boot 1.x, WebSockets and React, gradle, nodejs, spring-boot, gradle multi project, spring-mvc, spring-data, gradle dependency update plugin, react-router
Stars: ✭ 6 (-91.3%)
Mutual labels:  webpack, spring-boot
Jhipster5 Demo
Get Started with JHipster 5 Tutorial and Example
Stars: ✭ 80 (+15.94%)
Mutual labels:  webpack, spring-boot
Spring Boot Angular4 Boilerplate
Quickstart for spring boot + angular 4 projects
Stars: ✭ 151 (+118.84%)
Mutual labels:  webpack, spring-boot
Boot Spring Boot
'Boot Spring Boot: 스프링 부트 시작하기' 예제
Stars: ✭ 85 (+23.19%)
Mutual labels:  spring-boot, sample
One
基于Spring Boot和Vue2开发的前后端分离的后台管理系统
Stars: ✭ 426 (+517.39%)
Mutual labels:  webpack, spring-boot
Generator Jhipster
JHipster is a development platform to quickly generate, develop, & deploy modern web applications & microservice architectures.
Stars: ✭ 19,162 (+27671.01%)
Mutual labels:  webpack, spring-boot
21 Points
❤️ 21-Points Health is an app you can use to monitor your health.
Stars: ✭ 244 (+253.62%)
Mutual labels:  webpack, spring-boot
Subnode.org
SubNode: Social Media App
Stars: ✭ 25 (-63.77%)
Mutual labels:  webpack, spring-boot
Great Big Example Application
A full-stack example app built with JHipster, Spring Boot, Kotlin, Angular 4, ngrx, and Webpack
Stars: ✭ 899 (+1202.9%)
Mutual labels:  webpack, spring-boot
Sample Spring Boot Javafx
Рыба Spring Boot + JavaFX
Stars: ✭ 59 (-14.49%)
Mutual labels:  spring-boot, sample
Extracted Loader
It reloads extracted stylesheets extracted with ExtractTextPlugin
Stars: ✭ 67 (-2.9%)
Mutual labels:  webpack
App Template
Boilerplate for Angular apps
Stars: ✭ 67 (-2.9%)
Mutual labels:  webpack
Ghosttheme Stockholm
👻 📝 ✨ Clean Ghost theme with advanced features & customization.
Stars: ✭ 67 (-2.9%)
Mutual labels:  webpack
Plasma
An Android Application written using latest Android Jetpack components and best practices, which displays trending movies/TV shows and cast, user can search movies and TV shows and also add them to watchlist.
Stars: ✭ 67 (-2.9%)
Mutual labels:  sample
Kotlin Graphql Sample
Sample implementation of Kotlin+Spring+GraphQL
Stars: ✭ 69 (+0%)
Mutual labels:  spring-boot
Cordovue
A sample Apache Cordova application using VueJS.
Stars: ✭ 66 (-4.35%)
Mutual labels:  webpack

目的

サーバーサイドエンジニアが気軽に vue.js + spring-boot で SPA 開発するためにはどうしたらいいか、という話。

登場するコンポーネントは以下のものたち。

  • spring-boot(Java の web application framework)
  • webpack(複数の JS をくっつけたりします)
  • npm(js の package manager)
  • babel(ES2015 を昔ながらの JS に変換するのに使います)
  • vue.js(簡単便利な js frameworkで、弊社社内でメインで利用されてるやつ)

ディレクトリ構造は以下のようにします。

src/main/java/                        ← java code
src/main/js/                          ← JS code
build/resources/main/static/bundle.js ← 成果物

最終的には webpack の成果物が含まれる uber jar(fat jar ともいう)が ./gradlew build で生成されるようにします。

セットアップ

node.js を最新版にしてください。

webpack をインストールします。

npm install -g webpack

まず、npm install で、package.json という npm の設定ファイルを生成します。

npm install -y

開発時に必要なライブラリ・アプリケーションをインストールします。 --save-dev オプションは、インストール後に package.json に開発時依存項目として追記するためのオプションです。

npm install --save-dev webpack babel-core babel-preset-es2015 babel-loader \
    vue-loader vue-style-loader vue-html-loader vue-template-compiler \
    file-loader style-loader url-loader css-loader \
    extract-text-webpack-plugin webpack

vue.js, vue-router という、実行時に利用するライブラリをインストールします。 --save オプションは、インストール後に package.json に依存項目として追記するためのオプションです。

npm install --save vue bootstrap vue-router axios

webpack の設定

webpack は JS/CSS 等の静的コンテンツを依存も含めて1つのファイルにまとめてくれるアプリケーションです。 babel 等の前処理も webpack で呼び出します(babel は transpiler framework で、主に ES2015 を古いブラウザでも実行できるようにするために利用されています)。

ExtractTextPlugin は、CSS ファイルを別ファイルとして書き出すために利用しています。

const webpack = require("webpack");
const ExtractTextPlugin = require("extract-text-webpack-plugin");

module.exports = {
  entry: './src/main/js/app.js',
  output: {
    filename: 'bundle.js',
    path: __dirname + '/build/resources/main/static'
  },
  module: {
    loaders: [
      {
        test: /\.vue$/,
        loader: 'vue-loader'
      },
      {
        test: /\.js$/,
        use: 'babel-loader',
        exclude: /node_modules/
      },
      {
        test: /\.css$/,
        use: ExtractTextPlugin.extract({
          fallback: "style-loader",
          use: "css-loader"
        })
      },
      // bootstrap に含まれる font 等を data url に変換する。
      {test: /\.svg$/, loader: 'url-loader?mimetype=image/svg+xml'},
      {test: /\.woff$/, loader: 'url-loader?mimetype=application/font-woff'},
      {test: /\.woff2$/, loader: 'url-loader?mimetype=application/font-woff'},
      {test: /\.eot$/, loader: 'url-loader?mimetype=application/font-woff'},
      {test: /\.ttf$/, loader: 'url-loader?mimetype=application/font-woff'}
    ]
  },
  plugins: [
    new ExtractTextPlugin("styles.css"),
  ]
}
;

webpack は webpack コマンドを実行するだけで利用できます。 開発時には webpack -w とすると、プロセスが常駐し、ファイルの更新を監視して、更新があったらリビルドされるようになります。

gradle とのつなぎ込み

webpack を実行する gradle task を設定します。 ./gradlew build した時に、uber jar の中に webpack の成果物を埋めるような設定を行います。

buildscript {
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath 'com.moowork.gradle:gradle-node-plugin:0.12'
    }
}

apply plugin: 'java'
apply plugin: "com.moowork.node"

node {
    version = '6.6.0'
    npmVersion = '3.10.7'
    download = true
}

task webpack(type: NodeTask, dependsOn: 'npmInstall') {
    def osName = System.getProperty("os.name").toLowerCase();
    if (osName.contains("windows")) {
        script = project.file('node_modules/webpack/bin/webpack.js')
    } else {
        script = project.file('node_modules/.bin/webpack')
    }
}

processResources.dependsOn 'webpack'

clean.delete << file('node_modules')

./gradlew build すると webpack が実行され、jar の中にビルド済みの js が梱包されます。

npm run dev コマンドの設定

webpack -w を IntelliJ IDEA から呼び出しやすいように npm のサブコマンドを定義しておきます。 package.json に以下のように記述します。

{
  "name": "spring-vue-sample",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "webpack -w"
  }, // 以下略
}

こうすることにより、npm run devwebpack -w を実行できます。

SEE ALSO

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].