You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My assumption is that within this method we can have access to Rails.env so that we can test for the environment that would be within args:
defprocess_directives(directives)directives.eachdo |line_number,name, *args|
begin# If the target environment does not match the current environment# then skip the directiveifargs["target_environment"] && args["target_environment"] != Rails.env[args["target_environment"]]nextendsend("process_#{name}_directive", *args)rescueException=>ee.set_backtrace(["#{@filename}:#{line_number}"] + e.backtrace)raiseeendendend
The API for the directive would be something along the lines of
By default, the exclusion of target_environment would mean that the directive should apply to all environments. Perhaps multiple environments should be possible in one line too:
What drew me to this issue was GraphiQL from graphql-ruby which is only mounted in development and with the latest version of sprockets, the JS and CSS for GraphiQL would need to be added to the manifest.js file (//= link graphiql/rails/application.css) in all environments instead of just in development.
Actual behavior
Directives cannot be conditional depending on the Rails environment. Specifically for link_tree etc, assets are either pre-compiled in all environments or in none.
System configuration
Sprockets version - 4.0.2
Ruby version - 2.6.0
Example App (Reproduction) - THIS IS IMPORTANT YOUR ISSUE LIKELY WILL NOT BE RESOLVED WITHOUT THIS
Sorry, i just can't. If you have a proposal please send a PR or maybe write it up in your own library that extends sprockets or sprockets-rails. It's extremely hard for me to pre-approve any discussion without also seeing the code involved to implement it.
Expected behavior
This feature proposal would address (at least) these issues:
I am proposing amending the
process_directives
method inlib/sprockets/directive_processor.rb
which currently looks like:My assumption is that within this method we can have access to
Rails.env
so that we can test for the environment that would be withinargs
:The API for the directive would be something along the lines of
//= DIRECTIVE PATH EXTENSION target_environment=[production|development|test|*]
Example:
//= link_directory ../stylesheets/some_specific_sheet .css target_environment=development
By default, the exclusion of
target_environment
would mean that the directive should apply to all environments. Perhaps multiple environments should be possible in one line too://= link_directory ../stylesheets/some_specific_sheet .css target_environment=[development,test]
Or perhaps event an
exclude_environment
argument should be present:What drew me to this issue was GraphiQL from graphql-ruby which is only mounted in development and with the latest version of sprockets, the JS and CSS for GraphiQL would need to be added to the
manifest.js
file (//= link graphiql/rails/application.css
) in all environments instead of just in development.Actual behavior
Directives cannot be conditional depending on the Rails environment. Specifically for
link_tree
etc, assets are either pre-compiled in all environments or in none.System configuration
Example App (Reproduction) - THIS IS IMPORTANT YOUR ISSUE LIKELY WILL NOT BE RESOLVED WITHOUT THIS
Example of the
manifest.js
:The text was updated successfully, but these errors were encountered: