Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

manifest.js and dynamic assets to link #654

Closed
vfonic opened this issue Dec 4, 2019 · 7 comments
Closed

manifest.js and dynamic assets to link #654

vfonic opened this issue Dec 4, 2019 · 7 comments

Comments

@vfonic
Copy link

vfonic commented Dec 4, 2019

I just upgraded to sprockets 4 and, as many other developers, have had negative experience with the new manifest.js file requirement.

I also believe this change should have been done in a less breaking way. It could be a warning or, even better, the old behavior should continue working (I don't see what's stopping the old behavior from working?).

In my current, working, app. I have this in config/initializers/assets.rb:

Rails.application.config.assets.precompile += BulletTrain.available_apps.map do |app_name|
  app_symbol = app_name.parameterize.underscore
  [
    "apps/#{app_symbol}/#{BulletTrain::JAVASCRIPT_ASSET_NAME}",
    "apps/#{app_symbol}/#{BulletTrain::STYLESHEET_ASSET_NAME}"
  ]
end.flatten

This, based on the available_apps array, dynamically adds all the required assets for precompilation.

I upgraded sprockets, was met with the notorious error about missing manifest.js and tried to fix it:

# config/initializers/assets.rb
Rails.application.config.assets.precompile += ['manifest.js']
// app/assets/config/manifest.js.erb
<%= BulletTrain.available_apps.map do |app_name|
  app_symbol = app_name.parameterize.underscore
  [
    "//= link apps/#{app_symbol}/#{BulletTrain::JAVASCRIPT_ASSET_NAME}",
    "//= link apps/#{app_symbol}/#{BulletTrain::STYLESHEET_ASSET_NAME}"
  ]
end.flatten.join("\n") %>

I also tried:

# config/initializers/assets.rb
Rails.application.config.assets.precompile += ['manifest.js.erb']

But that also didn't work (Sprockets::Railtie::ManifestNeededError).

I also tried:

// app/assets/config/manifest.js.erb
//= link_tree ../stylesheets .css
//= link_tree ../javascripts .js

...which is not providing the same functionality (all apps' assets are not being precompiled, not only available apps)

But I hit a different bug that I'll open a new issue for (more on that below).

Expected behavior

The old behavior just works.

Actual behavior

There's no way to achieve the same functionality in the new release.

System configuration

  • Sprockets 4.0.0
  • Ruby 2.6.5

Example App (Reproduction)

I'm afraid I've discovered unrelated issue while trying to create example app:
https://github.com/vfonic/no-rockets-for-sprockets

If you start rails server, the app will fail (or it won't). It's intermittently failing. (I'll create a separate issue.)

I've also followed the UPGRADING guide:
https://github.com/rails/sprockets/blob/070fc01947c111d35bb4c836e9bb71962a8e0595/UPGRADING.md#manifestjs

I don't see manifest.js being added for precompilation after doing rails new. Is it necessary to add that manually to old apps? The upgrading guide seems to be confusing. I'd believe I have to add this, yet I see new rails apps work without having that added.

Related: #643

@thebravoman
Copy link

Hi @vfonic were you able to find a solution to this?

@vfonic
Copy link
Author

vfonic commented Mar 21, 2020

I've restricted sprockets to '< 4'. Far from ideal, but keeps my app working.

gem 'sprockets', '< 4'

@thebravoman
Copy link

Been there till now, but I need to switch to webpacker (because of a library with es6 modules that I have to use) and thought - why not upgrade sprockets along the way as webpacker does not solve a lot of the problems and even introduces more of them and you have to use both sprockets and webpacker. Turns out it is far from possible to upgrade sprockets and even expect the same feature set.

@vfonic
Copy link
Author

vfonic commented Mar 21, 2020

I use webpacker and sprockets in the same project. I'd advise you to try sticking to both and slowly completely switch to webpacker.

@ldonis
Copy link

ldonis commented May 18, 2020

@vfonic thanks for the workaround, looks like keep sprockets behind version 4 is the only way to keep this working:

Rails.application.config.assets.precompile += ["my_engine/namespace/*.css"]

@blarralde
Copy link

From the upgrade guide, and successfully tested in my own app, the following still works with Sprockets 4:

Rails.application.config.assets.precompile += ["my_engine/namespace/somefile.css"]

I migrated all the files and directories I could to manifest.js, and for one that was too tedious to do so (Ckeditor assets) I added the precompile directive as below. As far as I can tell it's working fine.

Rails.application.config.assets.precompile += Ckeditor.assets

@rafaelfranca
Copy link
Member

The old way still works. You can continue doing:

Rails.application.config.assets.precompile += BulletTrain.available_apps.map do |app_name|
  app_symbol = app_name.parameterize.underscore
  [
    "apps/#{app_symbol}/#{BulletTrain::JAVASCRIPT_ASSET_NAME}",
    "apps/#{app_symbol}/#{BulletTrain::STYLESHEET_ASSET_NAME}"
  ]
end.flatten

But you still need a manifest for when dynamic is needed.

@rafaelfranca rafaelfranca closed this as not planned Won't fix, can't repro, duplicate, stale Jun 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants