-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Precompiles #10
base: master
Are you sure you want to change the base?
Add Precompiles #10
Conversation
# def add_precompiles | ||
# end | ||
def add_precompiles | ||
gsub_file "config/environments/production.rb", "# config.assets.precompile += %w( search.js )", "config.assets.precompile += %w( polyfills.js )" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to keep the comment in the file for future reference and add the config line after it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The line above this has a comment explaining what it does: "Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)." And, since the example I removed is so similar to the new line, I don't think there's much value leaving it in. I assumed it was standard to remove the example in cases like this, but I can leave it in if it's not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand why you choose to replace the comment, but now after looking closely to this way of adding precompiles I see 2 problems with it:
- What if another generator wants to add an asset too to the precompiles? It might use the same kind of code and expect the comment to exist.
- What if the user has deleted this comment and added a custem asset to the precomiles?
I'm not so familiar with rails generators so I can't suggest a better way yet, but I hope you'll see why I think this implementation is a bit dangerous.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's a good point. I think the correct way to do might be something like:
application(nil, :env => "production") do "#{application_name}::Application.config.assets.precompile += %w( polyfills.js )" end
(from http://guides.rubyonrails.org/generators.html#application), but I'm not sure.
Thanks for the work on this. I was toying with the idea of just adding the configuration inside the gem, similar to this: https://github.com/indirect/haml-rails/blob/master/lib/haml-rails.rb#L7-11 However, I don't want to force the use of polyfills.js just by virtue of loading the gem. I think perhaps the best compromize is to generate a new initializer in config/initializers. That way it can be deleted. I also don't think you want to force env production since you have full control of what environment you run the precompile rake task. So presumably it only gets run on deploy to production (or staging) anyway. But I like to run it in development sometimes just to see if it's working. |
For some reason I thought config.assets.precompile was in application.rb, but its in production. So using @sidnair09s example might be a good option. Sorry. I'll try and get this implemented or merged in the next day or so. |
I think this is the only change required for precompilation to work.
Edit: I just saw issue 9. I'll leave this issue open in case you decide against using an initializer. Sorry for the duplication.