简体   繁体   中英

Adding 3rd Party JS/CSS libraries to a Rails App

In an attempt to keep from having to make thousands of different UI decisions my company has purchased a template that includes Bootstrap, JQuery UI, and perhaps hundreds of different CSS and JS files. All total we're talking over 160 MB of files.

I'm using Rails 4.2 and Ruby 2.0.

I'm a relative "noob" and haven't run into this situation before. My original thought was to go directory by directory and move the assets into the appropriate asset pipeline directories (images, javascripts, stylesheets). But, not only did that seem incredibly tedious, I'm sure some of these JS files have paths in them to other resources and I didn't want to get into debugging all of that.

So I'm now looking at both the lib and vendor directories. By definition vendor sounds like the right place. But, it has javascripts and stylesheets directories and it looks like I'll be getting into the same mess as above.

The lib directory looks like it might work. So I tossed all of the sub directories in the assets directory. Now the big question, how do I get my app to use it for all pages. Again, I'm a "noob" on this type of stuff.

I've searched the rails guides and stackoverflow and while I'm seeing pieces of what might work, I'm not seeing anything that's actually outlining how to do this and nothing I've tried has worked. The closest thing to what should work is adding the following to application.rb

config.autoload_paths += Dir["#{config.root}/lib/**/"]

I've also tried adding the following to my application.css file along with the corresponding entry in my application.js file:

*= require_tree ../../../lib/assets/.

But I get a Error compiling a CSS Asset whenever it stumbles upon a .js file since they're all intermingled.

Any assistance is greatly appreciated.

I finally ended up putting everything in the assets pipeline and it worked fine. It doesn't follow best practices of keeping vendor libraries separate, but it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM