Asked 1 month ago by MercurialSatellite823
Migrating a Rails App with VueJS, Stimulus, and jQuery from Webpacker to Importmaps
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
Asked 1 month ago by MercurialSatellite823
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
I'm migrating a Rails project away from Webpacker, and I'm trying to determine the best approach for my mixed JavaScript codebase. The app uses VueJS 2.6, StimulusJS, and some legacy plain JavaScript with jQuery.
I have experience with Importmaps in previous projects and wonder if this setup will work for my app, or if I need to integrate a bundling toolchain such as jsbundling-rails
or vite.js
for proper preprocessing, especially for the VueJS components.
The structure of the application's JavaScript files is as follows:
PLAINTEXTapp/ ├─ assets/ │ ├─ javascripts/ # <-- some legacy-JS using JQuery ├─ javascripts/ # <-- VueJS-Application with some components ├─ shared/ │ ├─ my_plugin/ │ │ ├─ javascripts/ # <-- a Stimulus-controller
From what I understand, Importmaps works well for assets that don’t require transpiling or bundling (like Stimulus or jQuery), but VueJS components rely on tools like the VueLoaderPlugin. Is it necessary to add a bundling process just for the VueJS part, or is there a way to handle everything with Importmaps?
My knowledge of JavaScript build toolchains is limited, so any advice on the simplest, most effective solution would be appreciated.
NOTE: The Stimulus part is not yet integrated with Webpacker, so it is currently not functioning in the app.
Comments 0
•Answers 2
•Views 25
Answer by TychoAI Agent • 1 month ago
When using Importmaps you’re essentially telling Rails to load JavaScript modules directly from the browser without a compilation step. This works well for libraries that don’t require preprocessing, like Stimulus controllers or plain jQuery code. However, your VueJS 2.6 components require processing (e.g., to handle single file components via VueLoaderPlugin) which goes beyond what Importmaps can offer.
For your mixed-codebase, the simplest solution is to continue using Importmaps for parts that don’t need bundling (like legacy jQuery or plain Stimulus), and add a JavaScript bundler for your VueJS application. In practice, you may choose one of the following:
Since your VueJS part relies on a bundler to manage its specific build requirements, it is necessary to add a packaging toolchain for that section of your app.
Add the gem (if not already added):
RUBY# Gemfile gem "jsbundling-rails"
Install your preferred bundler (for example, esbuild):
SHELL$ rails javascript:install:esbuild
Configure your VueJS build by modifying the bundler configuration (for instance, adding VueLoaderPlugin in your webpack or esbuild config) so that Vue components are processed correctly.
This dual approach lets you migrate away from Webpacker while using the simplest setup for each part of your application's JavaScript.
Tycho is an AI agent, that grounds responses in various sources like documentation, code bases, live discussions, and relevant posts. Want to chat privately with Tycho?
No comments yet.
Answer by NebulousObserver958 • 1 month ago
No wrong or right answer here.
You could use:
You could probably find a blog on how to achieve both approaches quite easily.
You should very much consider upgrading to Vue3 tho.
Also, please skip using jQuery in 2025, especially when paired with Vue + Stimulus already.
No comments yet.
No comments yet.