A powerful web-based tool that instantly converts vanilla HTML into Vue 3 Single File Components (SFC). Supports both Composition API and Options API with intelligent parsing of scripts, styles, and templates.
- π― Dual API Support: Convert to either Composition API or Options API
- π§ Smart Parsing: Automatically extracts and converts:
- Variables β
ref()(Composition) ordata()(Options) - Functions β Composable functions or methods
- Styles β Scoped CSS
- Templates β Clean Vue templates
- Variables β
- β‘ Real-time Conversion: Instant preview as you type
- π Copy to Clipboard: One-click copy of converted code
- π¨ Syntax Highlighting: Beautiful code editor with syntax highlighting
- π§ͺ Fully Tested: Comprehensive test suite with Vitest
- π Zero Dependencies: Pure TypeScript conversion logic
- Node.js 18+
- npm or yarn or pnpm
# Clone the repository
git clone https://github.com/IwuchukwuDivine/html_vue_converter.git
cd html_vue_converter
# Install dependencies
npm install
# Start development server
npm run devVisit http://localhost:3000 to see the app in action!
- Open the application in your browser
- Paste your HTML code into the left editor
- Select your preferred API style (Composition or Options)
- View the converted Vue component in the right panel
- Click "Copy Code" to copy to clipboard
You can also use the converter function directly in your code:
import convert from "./app/utils/convert";
const html = `
<!DOCTYPE html>
<html>
<body>
<h1>Hello World</h1>
<button onclick="greet()">Click me</button>
<script>
function greet() {
alert('Hello!');
}
</script>
</body>
</html>
`;
// Convert to Composition API
const vueComponentComposition = convert(html, "composition");
// Convert to Options API
const vueComponentOptions = convert(html, "options");
console.log(vueComponentComposition);<!DOCTYPE html>
<html>
<head>
<style>
.container {
padding: 20px;
}
</style>
</head>
<body>
<div class="container">
<h1>Counter: <span id="count">0</span></h1>
<button onclick="increment()">+</button>
</div>
<script>
let count = 0;
function increment() {
count++;
document.getElementById("count").textContent = count;
}
</script>
</body>
</html><template>
<div class="app-wrapper">
<div class="container">
<h1>Counter: <span id="count">0</span></h1>
<button onclick="increment()">+</button>
</div>
</div>
</template>
<script setup lang="ts">
import { ref } from "vue";
// Reactive state (converted from variables)
const count = ref(0);
// Functions
function increment() {
count.value++;
document.getElementById("count").textContent = count.value;
}
// TODO: Review and adjust the converted code
</script>
<style scoped>
/* Converted styles - review and adjust */
.container {
padding: 20px;
}
</style>This project includes comprehensive tests using Vitest:
# Run tests
npm test
# Run tests in watch mode
npm test -- --watch
# Run tests with coverage
npm test -- --coverageThe test suite includes:
- β Basic HTML to Vue template conversion
- β Script extraction and conversion (variables & functions)
- β Style extraction and preservation
- β Both Composition and Options API outputs
- β Edge cases and error handling
- β Complex nested structures
- β Multiple script/style blocks
html_vue_converter/
βββ app/
β βββ assets/
β β βββ css/
β β βββ main.css # Global styles
β βββ components/
β β βββ CodeEditor.vue # Monaco-based code editor
β β βββ Header.vue # App header
β βββ pages/
β β βββ index.vue # Main converter page
β βββ utils/
β β βββ convert.ts # Core conversion logic
β β βββ convert.test.ts # Comprehensive tests
β β βββ test-files/ # HTML test fixtures
β βββ app.vue # Root component
βββ public/
β βββ logo-trans.png # App logo
βββ nuxt.config.ts # Nuxt configuration
βββ package.json # Dependencies
βββ tsconfig.json # TypeScript config
βββ README.md # This file
We welcome contributions! Here's how you can help:
- π Report Bugs: Open an issue describing the bug and how to reproduce it
- π‘ Suggest Features: Share your ideas for new features
- π Improve Documentation: Help improve our docs
- π§ Submit Pull Requests: Fix bugs or add new features
-
Fork the repository on GitHub
-
Clone your fork:
git clone https://github.com/IwuchukwuDivine/html_vue_converter.git cd html_vue_converter -
Create a feature branch:
git checkout -b feature/amazing-feature
-
Make your changes and commit:
git add . git commit -m "Add amazing feature"
-
Write/update tests if applicable:
npm test -
Push to your fork:
git push origin feature/amazing-feature
-
Open a Pull Request on GitHub
- Use TypeScript for type safety
- Follow the existing code style
- Write descriptive commit messages
- Add tests for new features
- Update documentation as needed
# Install dependencies
npm install
# Run development server (with hot reload)
npm run dev
# Run tests
npm test
# Build for production
npm run build
# Preview production build
npm run preview- Nuxt 3 - The Vue Framework
- Vue 3 - Progressive JavaScript Framework
- TypeScript - Type-safe JavaScript
- Tailwind CSS - Utility-first CSS framework
- Pinia - State Management
- Vitest - Unit Testing Framework
- VueUse - Vue Composition Utilities
This project is licensed under the MIT License - see the LICENSE file for details.
- Inspired by the need to quickly migrate legacy HTML to Vue 3
- Thanks to all contributors who help improve this tool
- Built with β€οΈ for the Vue community
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Support for Vue 2 conversion
- JSX/TSX output option
- Better handling of event listeners
- Import statement detection and preservation
- Component composition detection
- Dark mode toggle
- Export as .vue file
- Multiple file conversion (batch processing)
- VS Code extension
β Star this repo if you find it helpful!
Made with β€οΈ by the community
