After bundle update
my Rails app fails to boot with:
Expected to find a manifest file in `app/assets/config/manifest.js` (Sprockets::Railtie::ManifestNeededError)
Looks like you've upgraded sprockets. The later version(s) of sprockets require what's called a manifest.js
file. You don't have one. You need to create one, and add in a few "directives".
In the old version of sprockets, big assumptions were made about what assets to bundle/concatenate** - this is what sprockets does btw.
"Sprockets, please"
abc
togetherxyz
admin.js
separate.Create the manifest.js file
$ mkdir -p app/assets/config
$ touch app/assets/config/manifest.js
(not the root rails directory)
Then copy and paste the following into the manifest.js file you just created:
//= link_tree ../images
//= link_directory ../javascripts .js
//= link_directory ../stylesheets .css
Those commenty things //=
are called "directives".
If you haven't done so, pls review the sprockets documentation and save yourself some headaches. Small example below:
Let's translate the //= link_directory ../javascripts .js
directive:
"grab every js
file in the javascripts directory, concatenate them, and keep them as SEPARATE javascript files i.e. no bundling." If you want bundling, use a different directive.
You should also have a javascript_include_tag
, which is typically placed in your application.html.erb
file. If you have other files js files that are separately bundled, don't forget to add them to application.html.erb
e.g.:
<%= javascript_include_tag "application", "addOtherFiles", "here", "etc", "data-turbo-track": "reload", defer: true %>
If you have a precompile array in your app/config/environments/production.rb
folder (see below for an example) then perhaps you should move them over to your manifest.js
if they are not already accessed above.
config.assets.precompile = ["admin.js", "admin.css"]
Presumably you will want your admin.js
javascript file separate from your application.js
file. No problem, just tell sprockets to keep them separate:
//= link_tree ../images
//= link_directory ../javascripts .js
//= link_directory ../stylesheets .css
//= link "admin.js"
Reference: read here for further details re: manifest.js. file
Source: Thanks to Richard Schneeman's blog - see here for more information..
EDIT: if things are confusing / not clear: complain loudly! How can I fix if you keep mum? everyone benefits by these improvements.