jwhitley / requirejs-rails

RequireJS support for your Rails 3 or 4 application
MIT License
592 stars 202 forks source link

requirejs precompile not supported with es6 files from sprockets-es6 gem #241

Open chenxeed opened 9 years ago

chenxeed commented 9 years ago

Hi.

I installed both sprockets-es6 and requirejs-rails in my Rails app.

I changed some of my javascript files to .es6 extension so that Rails asset pipeline can compile those files to .es5 from gem sprockets-es6.

Those files also loads normally on requirejs-rails development mode, but unfortunately it returns error on precompiling. The error is something like this:

{ [Error: Error: ENOENT, no such file or directory '/home/chenx/Projects/piktov2-rails/tmp/requirejs/dst/view/templates.js'
In module tree:
    controller/templates

    at Object.fs.openSync (fs.js:432:18)
]
  originalError: 
   { [Error: ENOENT, no such file or directory '/home/chenx/Projects/piktov2-rails/tmp/requirejs/dst/view/templates.js']
     errno: 34,
     code: 'ENOENT',
     path: '/home/chenx/Projects/piktov2-rails/tmp/requirejs/dst/view/templates.js',
     syscall: 'open',
     fileName: '/home/chenx/Projects/piktov2-rails/tmp/requirejs/dst/view/templates.js',
     moduleTree: [ 'controller/templates' ] } }

The file can't be found because it is already named as .es6, hence: /view/templates.es6 and precompiler can't find it.

Need any assistance or suggestions here to support both gems. Thank you :)

chenxeed commented 9 years ago

What I was wondering, is it possible that the assets that we're going to digestify and compress is the file from sprockets, instead of fresh file copy? Since if we get the file from sprockets, it will be transpiled to es5.

chenxeed commented 9 years ago

I tried to tweak some changes, and it seems work for me. I made a pull-request about this, hopefully it's valid. If so, I can go back to use master branch as my Gem. (Right now I used my branch forked from requirejs-rails master branch)

https://github.com/jwhitley/requirejs-rails/pull/243

carsomyr commented 9 years ago

@chenxeed Thanks for this. I'll have to read up on transpiling.

chenxeed commented 9 years ago

@carsomyr You're welcome! :) will love to hear your feedback about this.

neoeno commented 9 years ago

This would be super-great to have — for me it's the last missing piece to getting ES2015 modules to work in Rails. Just say if there's anything I can do to help move this along.

chenxeed commented 9 years ago

I've closed my previous PR and reopened it. Rebased and only took 1 commit to change :)

https://github.com/jwhitley/requirejs-rails/pull/251