How to avoid precompiling in Rails >= 3.1 asset pi

2020-07-30 03:48发布

I precompiled my files in the asset pipeline after upgrading to rails 3.1 (and later to 3.2) Now (working in development mode) I have to recompile them after every change to see them appear. As this takes about one minute, development is nearly impossible.

I have made the following relevant entries in config/development.rb

config.cache_classes = false

# Show full error reports and disable caching
config.consider_all_requests_local       = true
config.action_controller.perform_caching = false

# Do not compress assets
config.assets.compress = false

config.assets.compile = true

# Expands the lines which load the assets
config.assets.debug = true

# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict

# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
config.active_record.auto_explain_threshold_in_seconds = 0.3

# configuration option config.assets.logger to control Sprockets logging
config.assets.logger = nil

What is wrong? How can I see the changes i make in application.js and others suddenly?

2条回答
疯言疯语
2楼-- · 2020-07-30 04:28

One has to manually do

 $ bundle exec rake assets:clean

Which will remove all files in [app]/public/assets/. (Caution with otherfiles there, belonging to a model (like users pics), they also get removed!).

When the files do not exist the original ones are used. So precompiling assets seems not necessary for development mode.

Thanks @shingara for the hint in his comment to the question.

查看更多
淡お忘
3楼-- · 2020-07-30 04:36

Something which might be a factor is if the following directive is in config/application.rb:

config.assets.precompile  += [ 'asset-file', ... ]

This should either be limited to 'fixed' asset files, or moved to config/environments/production.rb.

Not sure if that is happening with your situation, however it would produce similar results of not seeing changes after editing the asset file. Not precompiling assets will save you from needing to compile them each iteration in development.

查看更多
登录 后发表回答