Using importmaps instead of Webpack, eliminating the requirement of Nodejs #1636
Replies: 2 comments 5 replies
-
Sidebar SuggestionMaybe there's something I'm missing, but the tasks you added in your POC could be moved into the library. Back to the big pictureI've never used importmaps before, but I appreciate the simplicity of it and trust Rails to make pretty good decisions on stuff like this. I'm definitely down to use this instead of webpack when it's ready! |
Beta Was this translation helpful? Give feedback.
-
How do dependency bumps work with importmaps? Will Dependabot-like things not be an option? |
Beta Was this translation helpful? Give feedback.
-
Goal
For any-size Lucky projects, it would be nice to use importmaps instead of Webpack, as it could eliminate the need for Nodejs, making the experience more streamlined and less complicated, while also giving Lucky more control of the build pipeline.
Why
Besides the hype around Rails 7 switching to importmaps, this can be a good change to introduce for new projects, as the barrier to entry is much lower not needing to use Nodejs and Yarn. These tools are required for Lucky, but not all development teams are in the Node ecosystem, and so they feel like crutches to support the newer types of tooling.
Of course, these tools might be used in projects anyway, but what I'm suggesting is that they aren't required to start.
Show me the POC
After implementing a basic importmap concept, along with a few Lucky tasks, I created a POC of the usage.
I based my inspiration around importmap-rails for the most part, but tried to stick with what was necessary for the POC.
How it works
lucky importmap.pin react react-dom
. This will create the importmap if not already there, and pin those dependencies to their CDN url.lucky importmap.pin react --download
. This will do the same as the above, but will download the files from the CDN url into a vendor folder. It also prefixes the file content with a version of what the package is (since you don't have the URL with this approach).lucky importmap.unpin react-dom
. This will remove those dependencies from the importmap and the associated vendor files.lucky importmap.json
. This just shows the json file.es-module-shim
, so I actually just included it in my importmap, but use the url directly.<link>
tag with that module url, allowing it load before anything else.That was a lot of information haha. Take some to digest it and try it out (the POC Lucky project uses no database, so it should be pretty easy to get started). I'm also on the Discord server for any questions. Thanks.
Beta Was this translation helpful? Give feedback.
All reactions