Automating Vue2 to Vue3 Migration with GoGoCode
This article explains how to use the GoGoCode AST‑based tool to automatically convert Vue 2 projects to Vue 3 by following the official migration guide, installing the CLI, running conversion commands, and applying a comprehensive set of transformation rules covering common break‑changes.
Vue 3 has been released for a while, and many developers are eager to adopt its Composition API and other new features, but most are still maintaining large Vue 2 codebases where a manual upgrade feels like renovating an old house.
The Vue team provides a detailed migration guide, but many of the required changes are repetitive and labor‑intensive, such as wrapping async components or renaming custom directive lifecycle hooks.
To automate these tedious tasks, the author leverages GoGoCode , an AST‑based code transformation tool that simplifies writing conversion logic.
First, install the CLI globally:
npm install gogocode-cli -gThen run the conversion on the src directory of a Vue project:
gogocode -s ./src -t gogocode-plugin-vue -o ./src-outThe tool parses .vue files, extracts template and script AST nodes, and applies transformation rules. Simple rules like async component conversion can be expressed as string replacements, while more complex changes (e.g., custom directive lifecycle updates) are also handled.
Example of a rule that replaces the old async component syntax with the new Vue.defineAsyncComponent API:
script
.replace('() => import($_$)', 'Vue.defineAsyncComponent(() => import($_$)')
.replace(`
() => ({
component: import($_$1),
$$$
})`,
`
Vue.defineAsyncComponent({
loader: () => import($_$1),
$$$
})
`);The author tested the conversion on the official Vue 2 demo project vue-hackernews-2.0 , and after a small post‑processing step the project runs successfully on Vue 3. The article includes a table listing roughly 30 conversion rules that cover most break‑changes, such as v-for with Ref arrays, async components, attribute behavior changes, custom directives, data/options, emits, lifecycle events, v‑model, and many others.
All transformation rules are open‑source, and the author invites feedback via GitHub issues, a DingTalk group, and the project’s repository. The source code and documentation are linked for readers to explore further.
Java Architect Essentials
Committed to sharing quality articles and tutorials to help Java programmers progress from junior to mid-level to senior architect. We curate high-quality learning resources, interview questions, videos, and projects from across the internet to help you systematically improve your Java architecture skills. Follow and reply '1024' to get Java programming resources. Learn together, grow together.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.