esbuild Vue Plugin

0.2.4 · active · verified Sun Apr 19

esbuild-plugin-vue provides basic support for processing Vue 3 Single File Components (SFCs) directly within esbuild build pipelines. It enables core features like `<script setup>` syntax, TypeScript integration within script blocks, and scoped CSS styles, allowing developers to leverage esbuild's speed for compiling Vue applications. As of version 0.2.4, it is considered pre-1.0, indicating ongoing development and potential for API changes without strictly adhering to semantic versioning until a 1.x release. The plugin differentiates itself by offering a lightweight, esbuild-native solution for Vue SFC compilation, aiming for simplicity and performance over the more extensive feature sets of dedicated Vue build tools like Vite or Vue CLI. It utilizes `@vue/compiler-sfc` under the hood to perform the actual Vue compilation. The package appears to be actively maintained, evidenced by recent updates and a call for sponsorship.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to integrate `esbuild-plugin-vue` into an esbuild configuration to compile a basic Vue 3 SFC with `<script setup>`, TypeScript, and scoped styles.

import { build } from 'esbuild';
import vue from 'esbuild-plugin-vue';
import path from 'path';
import fs from 'fs';

// Create a dummy Vue SFC for demonstration
const vueComponentContent = `
<template>
  <div>Hello from Vue, {{ message }}!</div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
const message = ref('esbuild-plugin-vue');
</script>

<style scoped>
div {
  color: #42b983;
}
</style>
`;
const entryPointPath = path.resolve(__dirname, 'src', 'main.ts');
const vueComponentPath = path.resolve(__dirname, 'src', 'App.vue');

fs.mkdirSync(path.dirname(entryPointPath), { recursive: true });
fs.writeFileSync(vueComponentPath, vueComponentContent);
fs.writeFileSync(entryPointPath, `import App from './App.vue'; console.log(App);`);

(async () => {
  try {
    await build({
      entryPoints: [entryPointPath],
      bundle: true,
      outfile: path.resolve(__dirname, 'dist', 'bundle.js'),
      plugins: [vue()],
      format: 'esm',
      logLevel: 'info'
    });
    console.log('Build successful!');
  } catch (e) {
    console.error('Build failed:', e);
  }
})();

view raw JSON →