sprockets-rails icon indicating copy to clipboard operation
sprockets-rails copied to clipboard

Allow using a custom assets configuration manifest

Open kennyadsl opened this issue 5 years ago • 10 comments

Ref https://github.com/rails/sprockets-rails/issues/369

Using Sprockets 4, at the moment, the only allowed path for the newly required configuration manifest is the default one (app/assets/config/manifest.js) and there is no way to change it.

This PR adds a way to change the default location by adding a new config.assets.config_manifest option, that could be set like this:

config.assets.config_manifest = File.expand_path('my_custom_path/config/manifest.js', __dir__)

Additional context

In Solidus, we use a custom dummy app to perform our specs. We need to configure the path with custom locations for the configurations files we use. This PR allows us to set a custom configuration manifest path, otherwise, we would not be able to be compatible with Sprockets 4.

Here are some relevant parts of our DummyApp, I hope it helps to contextualize our issue.

And this is the failed build output (only first lines are relevant) now that sprockets 4 is used.


This is my first contribution to this project so feel free to point out if I missed something important or how can I improve the PR. Thanks!

kennyadsl avatar Oct 10 '19 12:10 kennyadsl

here's an old discussion about this https://github.com/rails/sprockets-rails/issues/369 I really support to make this optional!

a few notes... the error message has to fixed https://github.com/rails/sprockets-rails/blob/49bf8022c8d3e1d7348b3fe2e0931b2e448f1f58/lib/sprockets/railtie.rb#L72 and there's a failing test https://github.com/rails/sprockets-rails/blob/e9ca63edb6e658cdfcf8a35670c525b369c2ccca/test/test_railtie.rb#L298

ahorek avatar Oct 10 '19 12:10 ahorek

Thanks, @ahorek! Not sure failure is related now.

kennyadsl avatar Oct 10 '19 13:10 kennyadsl

Looking twice, I don't think this is a good change since, if I got it correctly, the config.assets.manifest configuration was used as the location of the output manifest (.yml) after the precompile (searching for config.assets.manifest here).

Even if this is a somehow accepted solution, I think we should use another option to avoid messing with the old purpose of this configuration. Maybe something like config.assets.configuration_manifest?

kennyadsl avatar Oct 10 '19 13:10 kennyadsl

We need a different config for this. The assets.manifest is the location of the output manifest. Maybe config.assets.config_manifest?

rafaelfranca avatar Oct 10 '19 16:10 rafaelfranca

@rafaelfranca added a new config named config_manifest for this. Let me know if this works!

kennyadsl avatar Oct 11 '19 13:10 kennyadsl

Another improvement (maybe with another PR) could be falling back to the Sprocket 3 behavior (app.config.assets.precompile += [LOOSE_APP_ASSETS, /(?:\/|\\|\A)application\.(css|js)$/]) if the configuration manifest does not exist. Do we really need to raise an exception if the configuration manifest is not present in the host application? Thoughts?

kennyadsl avatar Oct 11 '19 14:10 kennyadsl

Yes, we need to raise an exception. LOOSE_APP_ASSETS is a proc and procs are not supported anymore in the precompile option.

rafaelfranca avatar Oct 11 '19 17:10 rafaelfranca

@rafaelfranca any updates on this by any chance? It'd be really great to have it! 🙏

aldesantis avatar Oct 23 '19 14:10 aldesantis

@rafaelfranca hey there, is there any thing I can do to move this forward?

kennyadsl avatar Nov 04 '19 21:11 kennyadsl

@rafaelfranca friendly ping if you have time to point me in a good direction to move things forward here. Thanks!

kennyadsl avatar Dec 02 '19 14:12 kennyadsl