LoginSignup
39
40

More than 5 years have passed since last update.

gulp 3.7 リリース: CoffeeScriptネイティブに

Posted at

今回のアップデートの目玉は、やはりCoffeeScriptなどのaltJSをデフォルトでサポートするようになった点です。その他、--tasks-simpleオプションが用意されたのは、gulpと連携したアプリを作ろうとしていた人には朗報です。(実際、経緯としてはgulp-appからのニーズで追加されました)

合わせて、gulpコマンドの自動補完が改善されています。今までのバージョンで自動補完を使っていない場合は、ぜひ。Bash, Zsh, Powershell対応です。

gulp

以下、リリース文を転載しておきます。

  • update vinyl-fs to remove BOM from UTF8 files
  • add --tasks-simple flag for plaintext task listings
  • updated autocomplete scripts to be simpler and use new --tasks-simple flag
  • added support for transpilers via liftoff 0.11 and interpret
    • just npm install your compiler (coffee-script for example) and it will work out of the box

altJSを使うには?

CoffeeScriptを使う場合、package.jsonのdevDependenciescoffee-scriptを追加します。

{
  <略>
  "devDependencies": {
    "coffee-script": "*",
  }
}

設定ファイルとして、gulpfile.js の代わりに、gulpfile.coffee を置きます。例としてはこんな感じでしょうか。ほとんど括弧なしで書けますね。

gulp         = require 'gulp'
autoprefixer = require 'gulp-autoprefixer'
minifyCss    = require 'gulp-minify-css'
rename       = require 'gulp-rename'

gulp.task 'css', ->
  gulp.src            './css/styles.css'
  .pipe autoprefixer  'last 2 versions'
  .pipe minifyCss     keepSpecialComments: 0
  .pipe rename        extname: '.min.css'
  .pipe gulp.dest     './css/'

CoffeeScript以外のaltJSでも、同様にdevDependenciesに追加して、gulpfileの拡張子を設定すれば、それだけでOKです。

利用可能なaltJS

gulp.jsは、liftoff経由でスクリプトをロードします。現状で対応しているのは、jsを含めて下記の6つです。

listoff

{
  '.co': 'coco',
  '.coffee': 'coffee-script/register',
  '.iced': 'iced-coffee-script/register',
  '.js': null,
  '.litcoffee': 'coffee-script/register',
  '.ls': 'livescript'
}

この定義は、liftoff内ではなくて、interpretを読みに行っています。別のaltJSを使いたい場合は、こちらにコミットすると良いかもしれません。

  • liftoff : Launch your command line tool with ease
  • interpret : A dictionary of file extensions and associated module loaders
39
40
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
39
40