LoginSignup
4
5

More than 5 years have passed since last update.

バックエンドアプリ用のgulp-skeletonをつくった

Last updated at Posted at 2015-02-28

今時あんまやらないと思うけど、やんごとなき事情からローカルファイルをサーバに同期して開発したかったので、gulp-rsyncを使ったファイル同期用のgulpfileをつくった。

構成

src以下にアプリを突っ込んで同期する。

.
├── gulp_config.json
├── gulpfile.coffee
├── node_modules/
├── package.json
└── src/

gulpfile.coffee

'use strict'

gulp    = require 'gulp'
rsync   = require 'gulp-rsync'
plumber = require 'gulp-plumber'

config = require './gulp_config.json'

gulp.task 'deploy', ->
  gulp
  .src 'src/**'
  .pipe plumber()
  .pipe rsync
    root: 'src' # コピー元ディレクトリ
    hostname: config.rsync.dst.host    # コピー先ホスト名
    destination: config.rsync.dst.path # コピー先ディレクトリ
    progress: true  # 転送情報を表示
    recursive: true # 再帰的にディレクトリを走査
    compress: true  # 圧縮する
    clean: true     # コピー先に存在しないファイルを削除
    exclude: [      # 除外ファイル
      '.git'
      '.gitignore'
      'node_modules'
    ]
  .on 'error', (message) ->
    console.log 'deploy Error', message

gulp.task 'watch', ->
  gulp.watch 'src/**', ['deploy']

gulp.task 'default', ['deploy']

gulp_config.jsonにサーバの設定書いておく感じ。.gitignoreでリポジトリから弾いてる。

{
  "rsync": {
    "dst": {
      "host": "{同期先サーバのホスト名}",
      "path": "{/path/to/directory/}"
    }
  }
}

ギッハブ

clngn/backend_gulp_skeleton

4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5