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

[Question] Install bower (hence npm) to manage JS dependencies installation #67

Closed
franckverrot opened this issue Mar 3, 2013 · 18 comments

Comments

@franckverrot
Copy link

In all recent projects, I am using bower to organize and install JS dependencies.

The strategy is to put all those dependencies in a git-ignored folders and let Sprockets find those dependencies.

Do you think it would be worth/sensible adding a new step when building Rails 3+ apps that would run bower install (right after bundle install) automatically so that the deps are part of the compiled container? Is there another way to approach this problem that I'm missing?

Thanks in advance and thanks for your awesome work!

@hone
Copy link
Member

hone commented Mar 3, 2013

This looks interesting. I haven't looked at doing JS dependencies at all in the ruby buildpack. How many deps are you typically pulling in? What does it look like when we don't run bower install? You just have to vendor them into your git repo?

@franckverrot
Copy link
Author

How many deps are you typically pulling in?

I'd say a dozen.

What does it look like when we don't run bower install?

Sprockets fails to run and raises an exception in development. The assets would not precompile in production. So things will look pretty bad.

You just have to vendor them into your git repo?

So bower needs a .bowerrc file:

// .bowerrc
{
  "directory": "app/assets/javascripts/vendor/components",
  "json":      "app/assets/javascripts/component.json"
}

The vendor/components directory would be git-ignored

# .gitignore
app/assets/javascripts/vendor/components

And the component.json would look like this

// app/assets/javascripts/component.json
{
  "name": "My App",
  "version": "1.0.0",
  "dependencies": {
    "jquery"               : "1.8.3",
    "jquery-ui"            : "1.9.1",
    "modernizr"            : "2.6.2",
    "select2"              : "release-2.1",
    "bootstrap"            : "2.1.1",
    "h5Validate"           : "latest",
    "spin.js"              : "latest",
    "bootstrap-datepicker" : "latest",
   ...
  }
}

Running bower install would populate your app/assets/javascripts/vendor/components directory with your dependencies.

Lately Sprockets learned how to talk to bower thru the component.json file. so that requireing dependencies allows some shortcuts.

Don't hesitate to ask more questions, I'll make myself available. I can't use Heroku on those projects where I use bower so...

Memory muscle makes it easy to type bundle install but I often forget to also run bower install. If we move forward with the use of bower in this buildpack, maybe Rails Core will be OK to create a rake task that would do both (rake dependencies for example). I checked Bundler to see if there was any hooks a la git to run extra commands after bundle install, but no luck. Am I right?

Thanks for considering this issue! 👍

@seanpdoyle
Copy link

I too am looking for a way to use bower in my heroku Rails app.

Keeping potentially huge JS/CSS projects out of version control would be a huge win in noise reduction and maintainability. The only downside if that it would make for slower deployments, since you'd download bower packages on each deploy instead of once up front.

Still think it would be worthwhile.

@hiroshi
Copy link

hiroshi commented Apr 11, 2013

I did a quick hack to use bower for my sinatra app.

Along with your component.json, added a Rakefile:

task "assets:precompile" do
  `(cd /tmp && curl -O https://heroku-buildpack-nodejs.s3.amazonaws.com/nodejs-0.8.19.tgz)`
  `(mkdir -p bin/nodejs && cd bin/nodejs && tar xzf /tmp/nodejs-0.8.19.tgz)`
  `(cd bin && ln -s nodejs/bin/node node)`
  `node bin/nodejs/bin/npm install`
end

And a package.json:

{
    "name": "your app",
    "version": "x.x.x",
    "dependencies": {
        "bower": "*"
    },
    "scripts": {
        "postinstall": "./node_modules/bower/bin/bower install"
    }
}

I know it is a very dirty hack, but it does work for me.
Sorry, but it won't work with rails because assets:precompile is predefined. Maybe you can rename the new task and define a prerequisite for assets:precompile.

@0xqd
Copy link

0xqd commented Apr 19, 2013

@hiroshi interesting workaround. Do you have any idea to define a prerequisite for assets:precompile

@hiroshi
Copy link

hiroshi commented Apr 19, 2013

@rhacker try this.

task "bower_install" do
  ...
end

task "assets:precompile" => "bower_install"

@0xqd
Copy link

0xqd commented Apr 19, 2013

@hiroshi thanks for the suggestion. I will try and reply after that :)

@juno
Copy link

juno commented Apr 20, 2013

FYI: I created dirty hacked buildpack with node-0.10.3.

Repo: https://github.com/qnyp/heroku-buildpack-ruby-bower
Diff: qnyp/heroku-buildpack-ruby-bower@4fc981d...6d78198

@hiroshi
Copy link

hiroshi commented Apr 20, 2013

@juno
Nice work.
I encourage you to send a pull request even if it is not accepted.

@sanemat
Copy link

sanemat commented Jun 12, 2013

😍

@rubiii
Copy link

rubiii commented Sep 11, 2013

would have needed this as well yersterday. unfortunately, the solution proposed by @hiroshi did not work for me (i tried various node versions) due to a bug in an npm-library (i suspect). but this would definitely be nice to have!

@schneems
Copy link
Contributor

The most composable solution here would be to use the multi-buildpack and run node to install JS dependencies and the the ruby buildpack. If we're doing something that will now allow that from happening let us know. Right now it is not the usual case that a ruby app needs bower. There have been discussion of adding bower to rails on the rails-core mailing list, but ATM it's been decided that Rails should not adopt bower at this time. I would venture to say that if a major ruby framework (sinatra/rails) adds in support for a JS dependency manager, we'll add support for it then. For now use multi-buildpack and report problems. Closing this issue for now.

@hone
Copy link
Member

hone commented Sep 25, 2013

Interestingly enough, JS dep management is coming for Rails 4.1, so we
might have to implement something like this.

On Wed, Sep 25, 2013 at 1:25 PM, Richard Schneeman <notifications@github.com

wrote:

The most composable solution here would be to use the multi-buildpack and
run node to install JS dependencies and the the ruby buildpack. If we're
doing something that will now allow that from happening let us know. Right
now it is not the usual case that a ruby app needs bower. There have been
discussion of adding bower to rails on the rails-core mailing list, but ATM
it's been decided that Rails should not adopt bower at this time. I would
venture to say that if a major ruby framework (sinatra/rails) adds in
support for a JS dependency manager, we'll add support for it then. For now
use multi-buildpack and report problems. Closing this issue for now.


Reply to this email directly or view it on GitHubhttps://github.com//issues/67#issuecomment-25107247
.

@rubiii
Copy link

rubiii commented Sep 25, 2013

@hone that's interesting! do you know any details or did i miss a blog post announcing the plan?

@kenips
Copy link

kenips commented Oct 10, 2013

@hone couldn't find any details on JS dep management either. Any links / commits as pointers?

@hone
Copy link
Member

hone commented Oct 10, 2013

I only heard this in conversation, so I don't have any links :(

On Thu, Oct 10, 2013 at 12:04 AM, Ken Ip notifications@github.com wrote:

@hone https://github.com/hone couldn't find any details on JS dep
management either. Any links / commits as pointers?


Reply to this email directly or view it on GitHubhttps://github.com//issues/67#issuecomment-26027700
.

@pawelniewie
Copy link

+1 Having the same problem with missing bower :-(

@akshayrawat
Copy link

Opened #392 to discuss this, since this issue is fairly dated.

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