vite-plugin-makefile

raw JSON →
0.0.5 verified Fri May 01 auth: no javascript

Vite plugin that converts Makefile .PHONY targets into vite-plus tasks. Version 0.0.5 is the latest stable release. It automatically discovers Makefiles in specified directories, maps prerequisites to task dependencies, and supports prefix strategies for task names. Built on makefile-lossless via NAPI-RS for efficient parsing. Key differentiator: integrates Makefile targets directly into the vite-plus build system, eliminating the need to manually duplicate tasks. Compared to alternatives like just or taskfile, it reuses existing Makefiles without extra configuration. Limitations: only supports .PHONY targets, no variable expansion, pattern rules, or recursive make. Ideal for projects already using Makefiles that want to leverage vite-plus task execution.

error Error: Cannot find module 'vite-plugin-makefile'
cause The package is not installed or is installed but not found in node_modules.
fix
Run 'npm install vite-plugin-makefile' or 'vp add -D vite-plugin-makefile'.
error TypeError: Makefile is not a function
cause Importing the wrong export or using require() when the package is ESM-only.
fix
Use 'import { Makefile } from 'vite-plugin-makefile'' instead of CommonJS require().
error Error: Prefix strategy 'none' caused duplicate task name 'build'
cause Two Makefiles in different directories both define a .PHONY target named 'build'.
fix
Change prefix to 'directory' or provide a custom naming function to avoid conflicts.
gotcha Only .PHONY targets are converted to tasks. Non-phony targets (file targets) are ignored silently.
fix Ensure all desired targets are declared as .PHONY in your Makefile.
gotcha Variable expansion ($(VAR)), pattern rules (%.o: %.c), and recursive Make invocations are not supported. These are silently skipped or may cause incorrect behavior.
fix Avoid using these features in Makefiles intended for plugin use. Use the include option to manage subdirectories instead of recursive Make.
gotcha Conditional targets (ifeq / ifdef) are not supported. The plugin may misparse or ignore them.
fix Simplify Makefiles to avoid conditionals in .PHONY targets.
gotcha If prefix strategy is 'none' and two different directories produce the same target name, the plugin will throw an error to avoid name conflicts.
fix Use 'directory' prefix or a custom function to disambiguate task names.
gotcha The plugin relies on a NAPI-RS binding for makefile-lossless. This requires a compatible Node.js version and platform. On unsupported platforms, the plugin may fail to load.
fix Ensure your system meets the native dependency requirements (see napi-rs docs).
npm install vite-plugin-makefile
yarn add vite-plugin-makefile
pnpm add vite-plugin-makefile

Configures vite-plugin-makefile in a vite-plus project, scanning current and infra directories, excluding 'help' and 'default' targets, and using directory prefix for generated tasks.

import { defineConfig } from 'vite-plus';
import { Makefile } from 'vite-plugin-makefile';

export default defineConfig({
  plugins: [
    Makefile({
      include: ['.', 'infra'],
      exclude: ['help', 'default'],
      prefix: 'directory'
    })
  ],
  run: {
    tasks: {
      lint: { command: 'vp lint' }
    }
  }
});