Shopify / sprockets-commoner

Use Babel in Sprockets to compile JavaScript modules for the browser
MIT License
182 stars 22 forks source link

Advanced Configuration is Incorrect #29

Closed tanema closed 8 years ago

tanema commented 8 years ago

In the advanced configuration section of the read me it has this section of code:

Rails.application.config.assets.configure do |env|
  env.unregister_postprocessor('application/javascript', Sprockets::Commoner::Processor)
  ...
end

The unregister_postprocessor call is incorrect. It requires an instance of the processor, not just the class. I used the following code in my application to get it to work properly:

Rails.application.config.assets.configure do |env|
  env.postprocessors['application/javascript'].each do |processor|
    if processor.class == Sprockets::Commoner::Processor
      env.unregister_postprocessor('application/javascript', processor)
    end
  end
end

However I am not certain if this is the best way to do it since I think it is possible that env.postprocessors['application/javascript'] can be nil.

bouk commented 8 years ago

This is kind of an annoying part of sprockets, but the given code will work if the processor is not replaced by a processor by some other gem. I think I'll add a helper method to commoner to make this easier