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
Sometimes, you may want to link certain files only in certain environments. For example, we only want to render the GraphiQL views in our staging and development environment, and not production, or test.
If we do not add the above, in staging and development, we get the following error:
Asset `graphiql/rails/application.css` was not declared to be precompiled in production.
Declare links to your assets in `app/assets/config/manifest.js`.
//= link graphiql/rails/application.css
But now that we have added the above, in production and test, we get the following error when trying to precompile assets
$ RAILS_ENV=production bundle exec rake assets:precompilerake aborted!Sprockets::FileNotFound: couldn't find file 'graphiql/rails/application.css'Checked in these paths: /Users/arian/repos/my-app/app/assets/config /Users/arian/repos/my-app/app/assets/images /Users/arian/repos/my-appi/app/assets/javascripts /Users/arian/repos/my-app/app/assets/stylesheets
Existing config.assets.precompile settings will still work for string values (although it is discouraged), but if you were previously using regexp or proc values, they won't work at all with Sprockets 4, and if you try you'll get an exception raised that looks like NoMethodError: undefined method 'start_with?'
Is there a proper way, that is not discouraged to include link conditionally, lets say per environment?
System configuration
Sprockets version:
sprockets (4.1.1)
sprockets-rails (3.4.2)
Ruby version: ruby-3.1.3
Example App (Reproduction) - THIS IS IMPORTANT YOUR ISSUE LIKELY WILL NOT BE RESOLVED WITHOUT THIS
I can add an example app if needed
The text was updated successfully, but these errors were encountered:
arianf
changed the title
Conditional link in manifest.js (assets.precompile discouraged but currently only way)
Conditional link in manifest.js (assets.precompile discouraged)
Mar 31, 2023
The discouragement is from adding hundreds of files to config.assets.precompile because proc and regex are not supported anymore, it's fine for a couple of files. But you could have a conditional secondary manifest:
Sometimes, you may want to link certain files only in certain environments. For example, we only want to render the GraphiQL views in our
staging
anddevelopment
environment, and notproduction
, ortest
.So in our Gemfile we set:
And then we add to our
manifest.js
:If we do not add the above, in
staging
anddevelopment
, we get the following error:But now that we have added the above, in
production
andtest
, we get the following error when trying to precompile assetsThis was discussed a bit here: rmosolgo/graphiql-rails#13 (comment) and here rmosolgo/graphiql-rails#75 (comment)
And here is a suggested solution to the problem: rmosolgo/graphiql-rails#75 (comment)
But I was under the impression that we should be moving away from the
precompile
setting. https://github.com/rails/sprockets/blob/070fc01947c111d35bb4c836e9bb71962a8e0595/UPGRADING.md#manifestjsIs there a proper way, that is not discouraged to include
link
conditionally, lets say per environment?System configuration
ruby-3.1.3
Example App (Reproduction) - THIS IS IMPORTANT YOUR ISSUE LIKELY WILL NOT BE RESOLVED WITHOUT THIS
I can add an example app if needed
The text was updated successfully, but these errors were encountered: