Closed lelandcope closed 8 years ago
No, gulp-live-server
doesn't support coffee script out of the box, becase you can make it happen easily with other coffee packages. e.g. coffee-script
Im not sure I understand. The only way I can think of would be to compile it to js using the coffeescript package which I would rather not have to do just to run our test server. Am I missing another way of doing it?
We're on the same page, you need to compile coffeescript to javascript, it's not that complicated.
You just add few lines in your gulpfile using gulp-coffee
, something like this(not verified):
gulp.task('serve', ['gulp-coffee-task'] function(){
gulp.watch('my-server-script.coffee', 'gulp-coffee-task');
var server = gls.new('my-server-script.js');
gulp.watch('my-server-script.js', gls.start());
});
gulp.task('gulp-coffee-task', function() {
gulp.src('my-server-script.coffee')
.pipe(coffee({bare: true}).on('error', gutil.log))
.pipe(gulp.dest('.'))
});
The spirit of gulp plugin is solve a single problem, it should not try to give you everything especially there're good tools out there already. Please let me know if you get any problem get this working.
Hello and first of all: thanks for this great library!
Unfortunately, I do believe that supporting coffeescript is valuable (perhaps even elegant) here, as it avoids generating intermediary files which are semantically identical and can lead to cumbersome gulp files and/or unnecessary confussion during development and code management.
I myself, like using coffeescript to develop, but then I find cumbersome to translate it to JS. If you leave all the code together with the coffee, then you have to start issuing git rules to avoid introducing it into code versioning, you have to keep avoiding opening the .js files instead of the coffee by mistake and all your code folders get polluted. Then, if you opt for dumping everything into a "build" directory, you have to replicate the folder structure in which you store all your .coffee (for the "requires" to work as intended, that is), leading to a cumbersome gulp file... not nice either.
Just my opinion, and thanks again. Pedro.
I really would like the coffescript support. And I think you only need to change a few lines for it, namely:
https://github.com/gimm/gulp-live-server/blob/036c3afa2e9861c755c7be96e0fc817cdaf1d244/index.js#L124
Direct support for coffeescript (or other transpilers like livescript) has the huge advantage that the live-reloading feature is much faster, especially for me it is annoying because we have a network file system and it is considerably faster when it is not necessary to compile a lot of files.
If you want I could create a Pull Request.
For now I hacked the support into my gls. It is really ugly, but if anyone is interested. It exchanges the child_process.spawn function for the next call and uses my locally installed coffeescript instead of the process.execPath
and puts back the real spawn after it.
gulp.task 'webserver', ->
# Ugly HACK!! The next spawn call should use coffee and not node to spawn the server
cp = (require 'child_process')
realSpawn = cp.spawn
# overwrite the child_processes spawn
cp.spawn = (prog, args, options) ->
prog = realSpawn "node_modules/coffee-script/bin/coffee", args, options
# UNDO HACK!!
cp.spawn = realSpawn
return prog
# I'm not sure if you must load this library after hacking child_process?
gls = require 'gulp-live-server'
server = gls ['server/server.coffee', 'server/config.cson']
server.start()
@LittleHelicase please create a pull request for this, thanks in advance.
How about ?
gls = require 'gulp-live-server'
server = gls [
require.resolve('coffee-script/bin/coffee'), 'server.coffee'
]
server.start()
Can my server file be a coffeescript file or does it only support js files?