half-life
@half-life

Gulp.js и модульный coffeescript?

Подскажите как настроить gulpfile для сборки модулей написаных на coffeescript
Есть два файла
src/coffee/partials/extra.coffee
define [], ->
  "My string"

src/coffee/main.coffee
define ['partials/extra.coffee'], (extra)->
  console.log "Returned: #{extra}"


gulp пересобирает файл main.coffee Вот так сейчас выглядит мой таск для коффе
gulpfile.coffee
# ==============================
#   CoffeeScript
# ==============================

coffee = require 'gulp-coffee'
coffeelint = require 'gulp-coffeelint'
jshint = require 'gulp-jshint'
stylish = require 'jshint-stylish'
uglify = require 'gulp-uglify'

gulp.task 'coffee', ->
  gulp.src path.src.coffee
  .pipe plumber
    errorHandler: handleError
  .pipe do rigger
  .pipe do sourcemaps.init
  .pipe do coffeelint.reporter
  .pipe coffeelint.reporter('fail')
  .pipe do coffee
  .pipe do jshint
  .pipe jshint.reporter stylish
  .pipe do sourcemaps.write
  .pipe gulpif ifProd, do uglify
  .pipe gulp.dest path.build.js
  .pipe reload
    stream: true


как переделать таск, чтобы на выходе получался модульный js?
  • Вопрос задан
  • 1914 просмотров
Решения вопроса 1
half-life
@half-life Автор вопроса
Сам отвечу на свой вопрос

Вот такое решение.
gulpfile.coffee
bundler =  ->
  browserify
    entries: [ path.src.coffee ]
    extensions: ['.coffee', '.js']
    debug : true
  .transform 'coffeeify'
  .transform 'deamdify'
  .bundle()
  .on 'error', handleError
  .pipe source 'main.js'
  .pipe gulp.dest path.build.js
  .pipe reload
    stream: true

gulp.task 'coffee', ->
  gulp.src path.src.coffee, read: false
  .pipe plumber
    errorHandler: handleError
  .pipe tap bundler

src/coffee/partials/extra.coffee
define [], ->
  "My string"

src/coffee/main.coffee
define ['./partials/extra'], (extra) ->
  console.log "Returned: #{extra}"

Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы