-
Notifications
You must be signed in to change notification settings - Fork 120
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
Are there proposals for importmap-rails to work in rails 7 engines? #58
Comments
@jamesw As far as I can tell, having used the gem for testing and understanding purposes, engines and plugins are not supposed to provide their own I might be wrong though. |
I've been trying to get my engines working with Rails 7 and importmap and asset pipeline. It's really not clear between rails documentation and import-rails documentation what is the correct approach and where to put things (ie app/assets/javascripts or app/javascript) and what to include where (ie. index.js). Perhaps my confusion comes from never having to use webpacker (ever!). I did discover that pulling the javascripts directory out of the named space directory worked but the images and css still need to be namespaced. Not looking for any solution just yet just letting someone know the difficulties being encountered. |
I have tried again with the new Rails 7.0 release and I have still found no way to use impotmap-rails in an engine, surely this is going to be fixed? Can anyone on the rails team respond to this or give me pointers as to how to fix this, happy to do some work on it. |
Have you read the README? Is there an issue that this doesn't work? https://github.com/rails/importmap-rails#composing-import-maps |
@leehericks The link to that section of the README does not explain how to use importmap-rails inside an engine. Only how to make use of importmap-rails functionality provided by an engine, If you can follow my steps outlined in my opening post and make it work I would love to know how as would many others I suspect. There is NO documentaion at all as to how to set this up inside an engine whatsoever anywhere. I am not even able to find any github projects that might be doing this as, I guess, it is early days yet. |
I have an outstanding stackoverflow question here with a bounty if anyone cares to take a look |
hey @cpanderson @jamesw did you guys manage to make some progress with this issue? Still there is no documentation. I am able to nest/compose importmaps from the engine like @leehericks said, but I am not able to , for example , register stimulus controllers from a gem/engine. If you guys know how to do it and/or a repo with some examples would be great. I am willing to help/improve the documentation, but I need to understand things first 🤣 Many thanks |
In case someone is interested, there are a couple nice ideas in this repo https://github.com/creditario/nopassword . In particular the following engine importmap allows to load controllers the normal way ( eagerloading in controllers/index.js, etc) pin "application", to: "my_engine/application.js", preload: true
pin_all_from MyEngine::Engine.root.join("app/assets/javascripts/my_engine/controllers"), under: "controllers", to: "my_engine/controllers" |
That seems to work but some official documentation would be great. |
Related, it looks like there's an importmap failure when running |
I was doing this in a rails 6 engine and had to add the following within engine.rb
|
confirmed, I had to add similar entries on rails 7 too I had to import stimulus controllers from my custom engine, in engine' importmap.rb
and in engine.rb
|
For what it's worth, I've got the same issue in the test environment:
This is Rails 7, so no concept of |
A new engine with Rails 7 alpha 2, generated using
rails plugin new custom_page --mountable --full
generates a new engine that includes the importmap-rails gem in the bundled gems but there is no ability to use it. Addingspec.add_dependency 'importmap-rails'
to gemspec makes no difference. there is no importmap executable in the bin directory.A call to
bundle info importmap-rails
Produces
A call to
rails --tasks
listsrails app:importmap:install # Setup Importmap for the app
I was expecting to see the same without
app:
prefixA call to this task resolves to a template error
rails app:importmap:install
Hope this is a clear enough question for you. If there is a workaround solution to this I'd be grateful to hear it and I'm sure others will too. The reason for me wanting this is that I totally failed to introduced webpacker in a rails 6.1.4 engine and I was hoping this was going to be my, much improved, solution
Cheers
James
The text was updated successfully, but these errors were encountered: