LoginSignup
8
7

More than 5 years have passed since last update.

Gulp + Browserify + CoffeeScriptで複数エントリーポイントを登録する

Last updated at Posted at 2015-03-24

標題の環境で、エントリーポイントを複数登録するのに結構ハマりました。とりあえず無理矢理の対応です。
transform辺りについて、もっと熟知すれば効率よく書けるのかも。

gulpfile.coffee

gulp = require 'gulp'
browserify = require 'browserify'
glob = require 'glob'
notify = require 'gulp-notify'
source = require 'vinyl-source-stream'

path =
  source: 'develop/source'
  build: 'develop/build'

gulp.task 'browserify', ->
  # plumberの代替
  handleErrors = ->
    args = Array.prototype.slice.call arguments

    notify.onError
      title: 'Compile Error'
      message: '<%= error %>'
    .apply @, args

    @emit 'end'

  files = glob.sync "./#{path.source}/coffee/*.coffee"

  # エントリーポイントを複数登録するためのループ
  for i in files
    browserify
      entries: i
      extensions: '.coffee'
    .transform 'coffeeify'
    .bundle()
    .on 'error', handleErrors
    .pipe source i.replace(/.+\/(.+)\.coffee/g, '$1') + '.js'
    .pipe gulp.dest "#{path.build}/js/"

8
7
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
8
7