Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working inside a browser #11

Open
ycrepeau opened this issue Mar 19, 2017 · 3 comments
Open

Not working inside a browser #11

ycrepeau opened this issue Mar 19, 2017 · 3 comments

Comments

@ycrepeau
Copy link

I try to use teact in a Ruby on Rails application.

'require' is only supported by node, not by the Javascript engine running inside browsers.

I am trying to solve this issue with Browserify but Browserify seems to be unable to see the teact.coffee (renamed teact.js.coffee) file.

@hurrymaplelad
Copy link
Owner

Right! You'll need some sort of compilation pipeline that understands both commonjs requires and coffee script. I'm not super familiar with rails, but this might get you started:
https://github.com/goodeggs/teacup-rails

Links to projects or config files would help for more troubleshooting.

@mattlima
Copy link

mattlima commented Apr 13, 2017

I had the same issue and was in a rush, didn't want to establish a separate gulp/browserify/webpack/whatever pipeline. You can use teact in a few minutes with Rails with the following dirty hack:

  1. add teact.coffee to your assets/javascripts folder. Append the following to the end of the file to make sure Teact is 'exported' as a global:
window.Teact = Teact
  1. Add teact to the manifest in application.js (or wherever) the usual way:
//= require teact
  1. Grab whichever of Teact's bound functions you need in your local .coffee file, for example
{crel, pureComponent} = new Teact().tags()

Again, I cannot emphasize enough that this is a nasty hack, but if you're on a deadline it may help.

--EDIT--

Almost immediately after posting this I found I needed another npm lib in my rails project so I decided I needed a less hacky solution. This one worked for me: https://blog.ravenxce.com/using-npm-with-rails/

@jahbini
Copy link

jahbini commented Sep 27, 2017

Brunch has several skeletons that assemble coffeescript and js along with npm modules for the browser -- http://brunch.io/skeletons

oh, yes, it manages CSS stuff too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants