In this code base, I've started work on migrating and modernizing a Vue frontend. From Vue 2 to Vue 3. This is the last part of a larger job where I'm converting a Rails 5 + Vue 2 + Webpacker app into a Rails 8 + Vue 3 + Vite app. The backend work and foundational frontend setup is done. That is, Rails 8 and Vite are working. And Vue 3 has been already installed and configured; and, as a proof of concept, a small portion of the frontend code base has already been migrated and modernized and is working. This small portion is essentially the app's main layout, the router with one smoke-test route, a minimal pinia store that defines global app state, and some foundational Spraypaint models.
The new Vue 3 code is in the app/frontend directory, and it currently implements the small portion of the frontend that I mentioned above. Importantly, it demonstrates the general vision of what I want the final frontend code to be organized like, once everything is migrated. It demonstrates the overall architecture, the file structure, the code styling, the naming conventions, etc. Under the old_codebase directory, there's the original Vue 2 code. I've added it here for reference. I've extracted the files from the old Rails 5 + Vue 2 + Webpacker code base that are relevant to the frontend and put them there.
I want you to help me create a sort of "migration guide" document that captures the design decisions and conventions of how the new code base should be written. How the old code should be translated and be adapted to the new standards, conventions, and architecture. The purpose of this file is to serve as guidance for future agents and human developers to perform the migration work. I want it to read mostly like a series of rules explaining how to handle the migration of a particular type of component, or file, or situation, etc. The idea is for it to be tailored and specific to this code base, so it should not focus too much on known general Vue 2 vs Vue 3 changes. For that, we have the official migration guide. This is not that. This is a guide to modernize this particular code base. Like I said, the code in app/frontend already demonstrates some of the final vision.
I'm going to share some of the facts and decisions that I've been able to identify already. Help me prepare the document. Add anything more that you think are missing. And adapt the ones I give you if necessary to fit the document's tone and intent. Here's what I found/decided so far while working on the migration:
- The frontend code will have a new directory/file structure. It goes as follows:
- The
assetsdir will store image files and any other static assets. - The
componentsdir will store most of the Vue components used to compose the various screens. They will be stored as regularComponentName.vuefiles. - The
entrypointsdir will store the entry point files forViteto bundle. Onlyapplication.js,active_admin.jsandactive_admin.scssare meant to live here. They are already there. - The
filtersdir will store filter functions. - The
layoutsdir will store layout Vue components. This app has only one, which is already defined there:MainLayout.vue. - The
modelsdir will store theSpraypaintmodels. - The
routerdir will store the application router built usingvue-router. - The
storesdir will store this app's single store. - The
stylesdir will store any CSS/SCSS file that needs to be extracted. Only a_variables.scssis needed which is already there. - The
viewsdir will store all the Vue components which represent "views" (AKA "pages" or "screens"). These are the ones that the router's routes point to directly. - The
App.vuefile is the root Vue component.
- The
- The new code will use Vue's options API, like the old code. It won't use the composition API.
- Vue components go into
*.vuefiles named after the component, and into thecomponentsdir. Instead of how the old code did it. The old code used named directories after the components and usedindex.vuefiles inside of those directories. A weird setup that we will no longer use. - Filters are no longer supported in Vue 3 in the same way that they were in Vue 2 with "|" in templates. So we have to just call them as methods normally.
- The old code has a
loggercomponent. We wont use that in the new code. - The
vue-awesomepackage does not support Vue 3. It's been replaced by@fortawesome/vue-fontawesome. So the new code will use that instead. It's already been setup in the project. Components that need fontawesome icons will have to importFontAwesomeIconand use that. Luckily its a clean swap for the most part. - The
vue-breadcrumbspackage does not support Vue 3. And I haven't found an alternative that maps cleanly. We will need to find an alternative or implement something similar on our own. One of the tricky things is that it integrated with the old Vue router using thebreadcrumb:field in the route definitions. Let's not deal with this right at the beginning of work, leave this for towards the end. - The
vue-carouselpackage does not support Vue 3. And I haven't found an alternative that maps cleanly. We will need to find an alternative or implement something similar on our own. Let's not deal with this right at the beginning of work, leave this for towards the end. - The
vue-notificationpackage does not support Vue 3. And I haven't found an alternative that maps cleanly. We will need to find an alternative or implement something similar on our own. Let's not deal with this right at the beginning of work, leave this for towards the end. - The
spraypaint-vuepackage (https://github.com/graphiti-api/spraypaint-vue) does not support Vue 3. And I haven't found an alternative that maps cleanly. Apparently all this package does is enhance theApplicationRecord.sync = true;feature of Spraypaint so that instances are able to be properly garbage collected after they are done being used. It does this by calling#unlisten()when Vue components are being destroyed. The old code uses this, but the new one does not yet. I'd imagine this would cause memory leak problems, whenApplicationRecord.sync = true;is enabled. I'm not sure whether we actually need this. But if we do, we will need to figure out how to handle it in the new code. Maybe implement whatspraypaint-vuedoes ourselves, for Vue 3. Looking at the code fromspraypaint-vue, it doesn't look too complex. Let's not deal with this right at the beginning of work, leave this for towards the end. - The old code, in its app bootstrapping logic in
application.js, does a lot of weird things to load components and make them available globally. The new code wont do any of that. Components will be loaded explicitly when needed. - The old code used
vuexfor global state management. The new code usespinia. For the most part, this is a clean-ish swap. But still there are differences in how stores are defined and how vue components interact with the stores. For example,piniadoes not have mutations, so the old store and the components that interact with it will have to be rewritten to some extent to do things thepiniaway. Also, the new code will have only one store.piniasupports many but we will use only one. We have called it theAppStore. - The old code uses
actioncable-vueand the new one will too. Luckilyactioncable-vuesupports Vue 3 and it mostly seems like a clean-ish swap. But the way of doing certain things have changed. We need to upgrade and adapt. - The old code uses a few polyfills. The new code won't use any polyfills.
- The old code uses the event bus pattern, implemented using a Vue instance, to emit and listen to events across unrelated components. Vue 3 does not support this. So the new code will use the
mittandmitt-vuepackages. This is not at all set up yet.