Skip to content

Convert vanilla HTML to Vue 3 Single File Components instantly. Supports Composition API & Options API with smart parsing of scripts, styles, and templates. Built with Nuxt 3, TypeScript, and fully tested.

License

Notifications You must be signed in to change notification settings

IwuchukwuDivine/html_vue_converter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”„ HTML to Vue Converter

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.

License Open Source Helpers Vue Nuxt TypeScript

Demo of HTML to Vue Converter

✨ Features

  • 🎯 Dual API Support: Convert to either Composition API or Options API
  • 🧠 Smart Parsing: Automatically extracts and converts:
    • Variables β†’ ref() (Composition) or data() (Options)
    • Functions β†’ Composable functions or methods
    • Styles β†’ Scoped CSS
    • Templates β†’ Clean Vue templates
  • ⚑ 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

πŸš€ Quick Start

Prerequisites

  • Node.js 18+
  • npm or yarn or pnpm

Installation

# 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 dev

Visit http://localhost:3000 to see the app in action!

πŸ“– Usage

Web Interface

  1. Open the application in your browser
  2. Paste your HTML code into the left editor
  3. Select your preferred API style (Composition or Options)
  4. View the converted Vue component in the right panel
  5. Click "Copy Code" to copy to clipboard

Programmatic Usage

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);

Example Conversions

Input (HTML)

<!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>

Output (Vue Composition API)

<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>

πŸ§ͺ Testing

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 -- --coverage

Test Coverage

The 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

πŸ—οΈ Project Structure

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

🀝 Contributing

We welcome contributions! Here's how you can help:

Ways to Contribute

  1. πŸ› Report Bugs: Open an issue describing the bug and how to reproduce it
  2. πŸ’‘ Suggest Features: Share your ideas for new features
  3. πŸ“ Improve Documentation: Help improve our docs
  4. πŸ”§ Submit Pull Requests: Fix bugs or add new features

Development Workflow

  1. Fork the repository on GitHub

  2. Clone your fork:

    git clone https://github.com/IwuchukwuDivine/html_vue_converter.git
    cd html_vue_converter
  3. Create a feature branch:

    git checkout -b feature/amazing-feature
  4. Make your changes and commit:

    git add .
    git commit -m "Add amazing feature"
  5. Write/update tests if applicable:

    npm test
  6. Push to your fork:

    git push origin feature/amazing-feature
  7. Open a Pull Request on GitHub

Code Style

  • Use TypeScript for type safety
  • Follow the existing code style
  • Write descriptive commit messages
  • Add tests for new features
  • Update documentation as needed

Running Locally

# 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

πŸ› οΈ Built With

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • 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

πŸ“¬ Contact & Support

πŸ—ΊοΈ Roadmap

  • 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

About

Convert vanilla HTML to Vue 3 Single File Components instantly. Supports Composition API & Options API with smart parsing of scripts, styles, and templates. Built with Nuxt 3, TypeScript, and fully tested.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •