rails - concatante and minify css but ignore js - ruby-on-rails

Is it possible, using the asset pipeline on production, to seperate the minifcaiton & concatenation of js & css?
I want to have my css pre-compiled, but I'd like to leave my js files as they are in development.

In your application.js file you can remove the line:
//= require_tree .
Which causes the asset pipeline to ignore your individual javascript files for concentration.
You can manually add any file you wish to be included in the application.js file instead.

Related

grails asset pipeline plugin

I have read the documentation of Grails asset pipeline plugin so I started implementing it in a sample grails project built in 2.2.3. I installed the asset pipeline plugin version 1.7.1. My requirement is to include jquery.ui.min.js in my gsp file so I included by using the tag
<asset:javascript src="jquery-ui.min.js"/>.
Also, in my Config.groovy, I have made the following entry
grails.assets.bundle=true.
The problem which I am facing is that I'm unable to access the jquery.ui.min.js in my gsp file. Pease tell me what am I missing and how should I proceed with it as I could not get any valid solutions for my query??
I think you need to reference a different file:
<asset:javascript src="application.js"/>
And application.js contains:
//= require jquery-ui.min
at the top of the file (make sure there isn't any blank lines above that line, other comment lines are ok) to load your lib. See http://bertramdev.github.io/asset-pipeline/guide/usage.html#directives
This answer is a guess based on what Grails 2.4 gives me out of the box. FYI, the auto-generated application.js contains:
// This is a manifest file that'll be compiled into application.js.
//
// Any JavaScript file within this directory can be referenced here using a relative path.
//
// You're free to add application-wide JavaScript to this file, but it's generally better
// to create separate JavaScript files as needed.
//
//= require jquery
//= require_tree .
//= require_self

Where are the assets files related to the application layout in rails?

I know that for every controller, there's a separate SASS and CoffeeScript file to keep things organized. But what about styling the application layout itself? How is it that there's no files to put all the styling and JS related to the whole layout?
I know there's application.css and application.js, but I Know these are not to be messed with because these files put everything together.
I hope someone could put me in the right track!
the application.css and application.js are manifest file and there you can see require_tree . that load all your js file for application.js and in same manner for application.css now on compiling assets pipeline make a minified version of that and create only one file that hold all the js in itself if you want to create two manifest file you can also do that .

Pre Compile assets in different layout- Rails

In my rails application I have 3 layouts for different users. Every layout having some javascript and css files included in it.
I can't use following line in my application.js or application.css file
//= require_tree . or *= require_tree .
When I pre-compile all my js and css every thing is get disturbed in my site.
But I want to compile all my js and css files but compiling then together not working. Because when I compile all css files together then some of my classes are get override by other classes.
Even while pre compiling my assets its not giving me any error.
or I can only include those files in application.js or application.css which are common in 3 layouts. like this
//= require jquery-1.8.3
//= require jquery-migrate-1.0.0.js
//= require jquery-ui.js
But what if I to want pre compile my other js or css files which are not common in layouts?
Any Solution?
In config/environments/production.rb you can set, what do you want to precompile
config.assets.precompile << %w(admin.js admin.css user.js user.css)
From whatever i can get i think you want to have a different layout for different users. what you should do is remove require tree from your application.css and application.js files and require all the files which you want to have in your entire app and then for specific users you can simply render that layout

rails pipeline css file

I am using rails 3.2.12 and created a css file in assets/stylesheets/equipment.css to go along with a controller called equipment_controller.rb. This stylesheet isn't working. What do I need to do to get this included in the pipeline?
The file needs to be loaded into your application.css.
In your application.css file, you will either need to load the file manually (by adding require equipment to the manifest at the top of the file), or it will also be included if you have a require_tree line.
See http://guides.rubyonrails.org/asset_pipeline.html#manifest-files-and-directives for more information.
Make sure you have the *= require_tree . in your application.css. It will be responsible to include all stylesheets from the current directory.
I cleared the contents and changed the extension from .css to .css.scss. And now it works.

Link directly to compiled resource in asset pipeline?

I have a script that's basically a "widget" that users embed.
It's got just simple vanilla javascript and doesn't have any require's to other resources. It's located at /app/assets/javascripts/delivery.js
What I want to do is have the file get compressed/compiled and then let users link directly to it from a script tag, ie. <script src="http://example.com/assets/delivery.js"></script>
But right now...that's a no-go. That file doesn't exist in production.
So, how can I compress that file like any other JS file in the pipeline, and then link directly to it?
If you add
config.assets.precompile += ['delivery.js']
to your application.rb, then delivery.js will be treated as a manifest file: it will be precompiled and served up as delivery.js in production. Manifest files are often just a series of //= require (or //= require_directory) statements, but any javascript they contain will also be added to the generated file.
By default the application.js manifest includes everything - you way want to tweak this so that it doesn't include javascript which is intended only to be served standalone.
First, make sure that your app/assets/javascripts/delivery.js is not among the includes of your top-level "manifest" javascript file, i.e. app/assets/javascripts/application.js. application.js usually includes //= require_tree ., so it includes your delivery.js by default. You need to change that. Replace "require_tree" with individual "require" statements for all your assets that you want to have precompiled and combined in the application.js.
Next, update your environment files (config/environments/production.rb for production env) to include your file in the list of precompiled assets:
config.assets.precompile += %w( delivery.js )
Now you'll have it as a separate file in your public/assets directory, compiled and compressed in the same way as application.js. Just keep in mind that it has a digest attached to it's name similarly to your application.js (unless, of course, you serve the files without digests by setting config.assets.digest = false).

Resources