This plugin enables esbuild to process and bundle Vue 2 Single-File Components (SFCs). It specifically targets Vue 2, leveraging `vue-template-compiler` (a peer dependency) to compile `<template>`, `<script>`, and `<style>` blocks within `.vue` files into a format consumable by esbuild. The plugin offers features like CSS extraction, PostCSS processing, and can utilize Node.js `worker_threads` via `Piscina` for parallel compilation of multiple SFCs, which can enhance build performance for larger projects. The current stable version is 1.2.2, with its last update occurring in late 2022, suggesting a maintenance-oriented release cadence rather than active feature development. Its primary differentiator is its dedicated focus on integrating existing Vue 2 projects with the esbuild ecosystem, providing a lightweight and fast build solution without requiring an upgrade to Vue 3. It bridges the gap for projects still reliant on the Vue 2 framework, maintaining compatibility with its specific compilation requirements and ecosystem tooling, especially for scenarios where migrating to newer Vue versions is not immediately feasible. It's an alternative for projects looking to modernize their build pipeline using esbuild while remaining on Vue 2.
npm install esbuild-vueVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to set up `esbuild-vue` to compile a basic Vue 2 Single-File Component (SFC) into a browser-loadable JavaScript bundle, including the necessary HTML structure and a build script.
For Vue 3 projects, use an alternative like `@vue/compiler-sfc` or other dedicated esbuild plugins for Vue 3 SFCs.
Install `vue-template-compiler` alongside `vue`: `npm install vue@2.x vue-template-compiler@2.x`.
Always create a build script (e.g., `build.js`) and use `require('esbuild').build(...)` to configure and run esbuild with the plugin.Pass `{ isAsync: true }` to the plugin constructor: `plugins: [vuePlugin({ isAsync: true })]`.Add `define: { "process.env.NODE_ENV": JSON.stringify("production") }` to your esbuild options for production builds.Ensure `plugins: [vuePlugin()]` is present in your esbuild build options. Remember to call `vuePlugin()` as it returns the plugin object.
Install `vue-template-compiler` using your package manager: `npm install vue-template-compiler` or `yarn add vue-template-compiler`. Make sure its version matches your `vue` version.
Ensure both `vue` and `vue-template-compiler` are installed with matching major and minor versions (e.g., `vue@2.6.14` and `vue-template-compiler@2.6.14`).
Correct the plugin entry in your esbuild config from `plugins: [vuePlugin]` to `plugins: [vuePlugin()]`.