1

I have some third party modules in my node_modules folder in my Rails app.

I want to compile them as assets. So I'm doing:

Rails.application.config.assets.paths << Rails.root.join('node_modules')

# Only compile js and css files.
Rails.application.config.assets.precompile.push(Proc.new do |path|
  puts path
  File.extname(path).in? [
    '.js', '.css'
  ]
end)

In one of the node_modules, there is a file node_modules/somelib/src/style/main.scss (notice .scss). However, for some reason, this file is still being included in the assets. The output from the above puts path statement prints:

node_modules/somelib/src/style/main.css

What! Why is it changing it to .css when it is clearly a .scss file?

The reason I need to disable this behavior is that the .scss file in question has an @import statement that Rails doesn't know where to find (rightfully so, it wasn't meant for Rails's eyes.) So it throws an error. I need to exclude this scss file.

Snowman
  • 31,411
  • 46
  • 180
  • 303
  • May be you have some other rules in your `Rails.application.config.assets.precompile` You just add your path to the end of array. – djsmentya Jan 30 '18 at 16:32
  • better way to force js and css only compilation is `Rails.application.config.assets.precompile = %w(*.js *.css)` – djsmentya Jan 30 '18 at 16:34
  • here some examples https://stackoverflow.com/questions/10097993/rails-config-assets-precompile-setting-to-process-all-css-and-js-files-in-app-as – djsmentya Jan 30 '18 at 16:41
  • Same thing..Rails seems to convert the scss file to css _invisibly_ before it reaches this point. – Snowman Jan 30 '18 at 16:43

1 Answers1

-1

Sass is the most mature, stable, and powerful professional grade CSS extension language in the world. For more details - https://sass-lang.com/

I think stylesheet name extension may be change through this gem - https://github.com/rails/sass-rails