N
N
Nick V2015-04-19 20:46:10
CoffeeScript
Nick V, 2015-04-19 20:46:10

Gulp.js and modular coffeescript?

Tell me how to set up gulpfile to build modules written in coffeescript
There are two files

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

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


gulp rebuilds the main.coffee file This is how my coffee task looks like now
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


how to remake the task so that the output is modular js?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nick V, 2015-04-20
@half-life

I'll answer my own question
. Here's a solution.

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}"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question