nicosantangelo / sublime-gulp

Run Gulp tasks and use snippets from Sublime Text
https://sublime-gulp.nicosantangelo.com/
MIT License
155 stars 18 forks source link

Gulpfile in ES6 #62

Open yoiang opened 8 years ago

yoiang commented 8 years ago

Hey @NicoSantangelo !

My gulpfile is written in ES6 and I'm encountering this error:

(function (exports, require, module, __filename, __dirname) { import gulp from
                                                              ^^^^^^
SyntaxError: Unexpected reserved word
    at exports.runInThisContext (vm.js:73:16)
    at Module._compile (module.js:443:25)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at requireGulp (/Users/ian/Library/Application Support/Sublime Text 3/Packages/Gulp/write_tasks_to_cache.js:28:16)
    at Object.<anonymous> (/Users/ian/Library/Application Support/Sublime Text 3/Packages/Gulp/write_tasks_to_cache.js:83:12)
    at Module._compile (module.js:460:26)

It looks like sublime-gulp doesn't support ES6 at the moment. Are there plans in the future? Or is it another issue?

nicosantangelo commented 8 years ago

Actually it never came up as a desired feature but I like the idea. The problem is that the package has to run the gulpfile in order to get the tasks and be able to list them.

yoiang commented 8 years ago

By having the babel transpiler present using gulp directly (gulp run <blah>) works with our ES6 gulpfile.

This looks like an accurate tutorial to how we set ours up: http://macr.ae/article/gulp-and-babel.html

nicosantangelo commented 8 years ago

Hello again!

I created a test project with:

├── gulpfile.babel.js
├── .babelrc

Which has

$ cat .babelrc
{
  "presets": ["es2015"]
}
$ cat gulpfile.babel.js
import gulp from 'gulp';

gulp.task('default', () => console.log('Default task called'));

and I installed npm i --save babel-register babel-preset-es2015

After doing that, I can run gulp from both the command line and Sublime:

screen shot 2016-03-27 at 1 39 02 am

Am I missing something?

yoiang commented 8 years ago

That worked a ok running through the plugin?

Huh, then something else is messing with this on our end...

nicosantangelo commented 8 years ago

In the spirit of troubleshooting this, your gulpfile is called gulpfile.bebel.js?

I run into the save problem as you using ES6 and a gulpfile called gulpfile.js

yoiang commented 8 years ago

Arg, my mistake: so executing the default task or an arbitrary task works but getting a list of tasks does not, it seems to be creating a .sublime-gulp-tmp.js file, where this error is occuring.

nicosantangelo commented 8 years ago

Sublime Gulp works by creating a .sublime-gulp-tmp.js from which it extracts the gulp tasks.

The weird thing is that it looks like ES6 is being recognized in your project, but another issue makes it blow up, because the error says SyntaxError: Unexpected reserved word instead of SyntaxError: Unexpected token import.

If you don't mind, could you paste your gulpfile.babel.js here? (removing any sensible parts, if any) so I can give it a go