Is any way to prevent the compiling of specific *.scss files from assets/stylesheets? I need to keep those files in assets not public directory
you can remove
*= require_tree .
line from application.scss and require only the files you want to compile.
Related
When I run rake assets:prcompile RAILS_ENV=production, I am getting below error.But if i run in development mode it runs fine.
rake assets:precompile RAILS_ENV=production
rake aborted!
Uglifier::Error: fs redeclared
Environment
Rails 5.0.7
Ruby 2.4.1
Could someone helps to resolve this one
Got the issue.In my application.js file have below codes
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .
As per functionality of require_tree, it will include current path's all js files recursively. Refer the link https://guides.rubyonrails.org/asset_pipeline.html#manifest-files-and-directives
In JavaScript files, Sprockets directives begin with //=. In the above case, the file is using the require and the require_tree directives. The require directive is used to tell Sprockets the files you wish to require. Here, you are requiring the files rails-ujs.js and turbolinks.js that are available somewhere in the search path for Sprockets. You need not supply the extensions explicitly. Sprockets assumes you are requiring a .js file when done from within a .js file.
The require_tree directive tells Sprockets to recursively include all JavaScript files in the specified directory into the output. These paths must be specified relative to the manifest file. You can also use the require_directory directive which includes all JavaScript files only in the directory specified, without recursion.
In my application , Gruntfile.js file was declared in two js folders.So, when I was doing the precompile,as the file was declared in two js , it throws error when it tried to compress that file
I would like to keep Javascript controllers (Angular) next to Rails 4 controllers, in the same folder. I added this line to the config/initializers/assets.rb
Rails.application.config.assets.paths << Rails.root.join('app', 'controllers')
And restarted server (development env), but it didn't help. Javascript files are written in Coffee and work when in standard assets/javascripts folder.
Solved by adding one line in assets/javascripts/application.js
//= require_tree ../../controllers
I's because default require_tree . doesn't autoload all javascript files in asset pipeline, but only those in the "dot" folder of application.js, which is standard javascripts folder.
add this line to the application.js
//= require_directory .
It will include all js files in the app/assets/javascript directory recursively
I'm using a WYSIWYG called Bootsy. docs here: http://volmer.github.io/bootsy/
I did this command and got:
$ rails generate bootsy:install
route mount Bootsy::Engine => '/bootsy', as: 'bootsy'
create config/locales/bootsy.en.yml
insert app/assets/javascripts/application.js
not found app/assets/stylesheets/application.css not found. You must manually require Bootsy in your assets pipeline.
create config/initializers/bootsy.rb
In my Rails app I do have a file called application.css.scss so the only reason the install couldn't find the file was because of the .scss I'm wondering how to best address this issue.
My first guess was to do this inside my application.css.scss file:
require 'bootsy'
but I'm not sure if I'm supposed to do
*= require_bootsy
or
*= require 'bootsy'
or if I should just add an application.css file inside the pipeline that way it doesn't give me problems. Would that be bad to have an application.css AND an application.css.scss file inside my stylesheets folder?
According to the gem source you should use *= require bootsy
Here's the relevant code from https://github.com/volmer/bootsy/blob/master/lib/generators/bootsy/install_generator.rb
{
original: 'app/assets/stylesheets/application.css',
skip_if: 'require bootsy',
content: "\n *= require bootsy",
position: {
after: '*= require_self'
}
}
To precompile all css files in a project I could add this to production.rb:
config.assets.precompile << '*.css'
But how can I add only css files in a particular folder?
Add all stylesheets into your app/assets/stylesheets/application.css:
/*
*= require_self
*= require_tree dir_one
*= require_tree dir_two
*/
Then they will be precompiled. I think this is the preferred way over using config.assets.precompile.
If you really want to use it, this SO question should help: How do I use config.assets.precompile for directories rather than single files?
I want to separate out my javascripts into separate subdirectories in my Rails 3.1 app.
For instance I have a /modules directory inside /app/assets/javascripts
A way to either require all the contents of the directory or each file individually would be helpful.
Edit: To clarify, I want to do this from my application.js coffeescript file.
I believe the way to do this in Sprockets is
#= require_tree modules
or
#= require_tree ./modules
if you want to select a subdirectory relative to the CoffeeScript file, rather than relative to app/assets/javascripts (see this issue).