[Rails 7] - Help to configure a newly migrated app to process activeadmin assets (js and scss) using jsbundling-rails with esbuild #7947
Replies: 9 comments 10 replies
-
Hi I switched back to webpacker for the moment, because I can see that Active Admin is using jQuery UI and this library does not play well with esbuild by default I think this resource could be helpful: https://gorails.com/episodes/how-to-use-jquery-with-esbuild It requires to download custom assets from jquery-ui and I'm not comfortable in doing that Slightly refers to #7226 |
Beta Was this translation helpful? Give feedback.
-
I did some progress, everything is not tested but It is really promising. The goal is to compile in
Files tree
1/ In package.json, I have
application.tailwind.css: I regroup all my CSS this file
active_admin.scss
active_admin.js
|
Beta Was this translation helpful? Give feedback.
-
I wanted to get this working with rails 7 and esbuild and took the nuclear option 😅
And it works! It might have been possible to make it work with https://github.com/excid3/esbuild-rails but jquery-ui needs a custom build. If activeadmin can publish a gem with assets precompiled, it will be much easier to use. |
Beta Was this translation helpful? Give feedback.
-
I have a similar issue, although it is entangled with my limited understanding of the new Rails 7 css and js options. I created a new Rails 7 app with After installing and visiting |
Beta Was this translation helpful? Give feedback.
-
I successfully manage to install To handle the I've added the following snippet to mimic Webpacker methods the
Ensure you have
No issues so far, but I guess jquery-ui components would require explicit importing |
Beta Was this translation helpful? Give feedback.
-
Hi guys, sorry to resurrect this discussion but while this solution works like a charm inside Active Admin, I can't seem to get the sign in page working. I keep getting the following error:
I already removed most of the webpacker files and configs, but I can't seem to find the place to make this particular page working, which means I can't log in to Active Admin at all. Any help would be greatly appreciated! |
Beta Was this translation helpful? Give feedback.
-
Hi all, I've been back to this url several times in the last week, I wanted to report on my progress and what i think is a tenable solution for my needs. I started with the snippets from @guillaumebesse up there ☝️ . This was perfect to get me css / scss compiling and get me on the right track but as soon as i added inline forms that required javascript (has_many, nested attributes) is when I noticed the javascript was not getting built.
import "@activeadmin/activeadmin"; issue: web conole reports
solution (I think): declare the build to be a module in "module": "true",
"dependencies": {
"@activeadmin/activeadmin": "^3.0.0",
... Issue: jquery is not defined:
import jquery from 'jquery';
window.jquery = jquery; // i mean why not?!
window.jQuery = jquery; // jquery ui is looking for this one
window.$ = jquery; // activeadmin wants this one
import "./add_jquery" // forces hoisting to behave
import './jquery-ui' // jQuery is now defined
import "@activeadmin/activeadmin"; Final issue, jQuery UI when loaded from node_modules has a ton of load dependencies outside the initial widget.js, as you can see from the above import, I vendored jquery-ui instead of using it from the node modules. you can download the full version from the website. I finally came across this video which ended up being really useful to get that final step. % tree app/javascript
app/javascript
├── active_admin.js
├── add_jquery.js
├── application.js
├── controllers
│ ├── application.js
│ ├── hello_controller.js
│ └── index.js
└── jquery-ui.js Like often, javascript has taken hours off of my life, but I'm super grateful to not be in the business of building forms, so thanks ActiveAdmin folks. Hopefully this helps streamline the process for others on Rails 7 and esbuild. |
Beta Was this translation helpful? Give feedback.
-
I'm not sure if this is necessarily still an issue for people but i was able to get this resolved with two steps. This seems to be acceptable considering the new propshaft asset model handling: Roughly: transpile with dartsass-rails. That means running the set up for dartsass-rails and then i added a build step in
My initializer for
You should do the above to make sure that your application css won't get clobbered by active_admin css. nothing else is really needed, propshaft will deliver the correct asset once it's transpiled for active admin css to use because active admin is using stylesheet_link_tag i believe Then in the active_admin initializer you need to add this configuration:
I had trouble actually figuring out the javascript. I tried esbuild to bundle the smaller files but that was leading to some other issues with imports and what not and seemed like a rabbit hole. Credit for the javascript goes to Henrik on medium: https://henrikbjorn.medium.com/til-using-activeadmin-with-importmap-rails-289cde6f76b8 He also has a section on importmaps but i don't fully understand importmaps yet so ... anyways hope the above is helpful especially for people integrating activeadmin with rails 8. This seems to fully work, at least I tested one delete action and was able to successfully delete a resource on the admin backend. |
Beta Was this translation helpful? Give feedback.
-
tldr: To use Active Admin v3 with Propshaft, put https://gist.github.com/losnikitos/46b4fb8c63bfd14577299611ec90f61b into I had a problem with missing js bundle after migrating from Sprockets to Propshaft (Rails 7, Active Admin v3). My
Which Sprockets would have picked up and assembled a bundle, but Propshaft wouldn't. What I did was 'quick and dirty' solution: I assembled a bundle with sprockets ( |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Thanks to the work in progress in PR #7235, activeadmin is starting.
But I don't know how to deal with active_admin.js and my custom scss files.
I am new to esbuild.
Any help is welcome.
Beta Was this translation helpful? Give feedback.
All reactions