hi I am using my raw custom coded js in assets/javascripts/xx.js, when I imported jquery using importmap, its showing like "jQuery is not defined" in my custom js file, any idea to fix them?
It sounds like you're looking for a jQuery global object? You could have something like this: import $ from "jquery"; jQuery = $; but it should probably be something like this: window.$ = window.jQuery = $; I hope that helps.
@@velsvels701 I don't really know what you mean by that. That's basically how Javascript works. If you want to access an object/function from a different file (or library), you have to import it. Otherwise how would it know it exists?
@@mixandgo In some scenario, I need to use added my custom scripts for my project, when I used jquery using importmap, It wants me to convert code like added my custom scripts for my project, if I have 100 files then I need to replace all of them right? are there any workaround to fix that?
@@mixandgo Yes, unfortunately I spent several days trying to unwind a mish-mash of configs in a shakapacker+Vue on Rails + Yarn 1.something or other outdated-version recently. I cant wait to give this a go, looks brilliant
Perhaps You can make full tutorial step by step for beginner make website with rails and full with bootstrap or css such as website about gym website with membership or others, and probably You can publish into freecodecamp
Funny you talk about webpacker hell. I never wasted much time with webpacker - I'm on hour 6 of getting bootstrap to work with importmaps. THAT'S what I'd call hell.
@@mixandgo the new `--css=bootstrap` has worked a dream for setting up bootstrap CSS. On the other hand, none of bootstrap's JavaScript features are working. I've tried several sets of instructions on setting up rails 7 with bootstrap, but none have given me working JS. I'm convinced there is something wrong with my setup, as I have to manually set up importmaps (which some of the instructions suggest it is added by default) and then I end up with conflicting application.js files. I have one in app/javascript/ and one in app/assets/build/. I'm currently reinstalling everything hoping that will fix it.
@@peytonsterling2497 well the `--css=bootstrap` option installs esbuild instead of importmaps. So once you have esbuild, there's no point in trying to install importmaps. The purpose of importmaps is so you don't bother with of the JS bundling stuff.
Here's a quick test, I just created a new Rails app using --css=bootstrap share.cleanshot.com/DsrTI1 (I used the modal example from the bootstrap docs) didn't change anything else.
@@mixandgo It's becoming more and more clear to me, that I have no idea what I am doing :') forgive me if this is obvious: if i want to use importmaps, I should not use the --css flag and manually add bootstrap? Thanks for your time