vite-plugin-makefile

Vite plugin that converts Makefile targets into vite-plus tasks

13
0
13
TypeScript
public

vite-plugin-makefile

[!CAUTION]
Vite+ is currently in alpha and its plugin APIs (especially the run.tasks config hook) are subject to breaking changes. Do not use this plugin in production yet. This plugin will be ready for use once Vite+ reaches a stable release.

[!WARNING]
This plugin does not work yet. The run.tasks configuration via the plugin config hook relies on voidzero-dev/vite-plus#1213, which has been reverted. The underlying vite.config API is still under discussion in vitejs/vite#22085. This plugin will be functional once the upstream API is finalized and re-landed.

npm
CI

Vite plugin that converts Makefile targets into vite-plus tasks

✨ Features

  • ✅️ Automatically discovers .PHONY targets from Makefiles
  • ✅️ Converts prerequisites into dependsOn task dependencies
  • ✅️ Supports multiple directories with prefix strategies
  • ✅️ Powered by makefile-lossless via NAPI-RS binding

💿 Installation

vp add -D vite-plugin-makefile

🚀 Usage

// vite.config.ts
import { defineConfig, lazyPlugins } from 'vite-plus'
import { Makefile } from 'vite-plugin-makefile'

export default defineConfig({
  plugins: [
    lazyPlugins(() => {
      return [
        Makefile({
          include: ['.', 'infra'],
          exclude: [],
          prefix: 'directory'
        })
      ]
    })
  ],
  run: {
    tasks: {
      // Merged with plugin-generated tasks
      lint: { command: 'vp lint' }
    }
  }
})

Given the following project structure:

project/
├── Makefile          # .PHONY: build test clean setup
├── infra/
│   └── Makefile      # .PHONY: docker-up docker-down migrate
└── vite.config.ts

The plugin generates the following tasks:

{
  "build": { "command": "make build", "dependsOn": ["setup"] },
  "test": { "command": "make test", "dependsOn": ["build"] },
  "clean": { "command": "make clean" },
  "setup": { "command": "make setup" },
  "infra/docker-up": { "command": "make docker-up", "cwd": "infra" },
  "infra/docker-down": { "command": "make docker-down", "cwd": "infra" },
  "infra/migrate": { "command": "make migrate", "cwd": "infra", "dependsOn": ["infra/docker-up"] }
}

⚙️ Options

include

  • Type: string[]
  • Default: ['.']

List of directories to scan for Makefiles (relative to workspace root).

exclude

  • Type: string[]
  • Default: []

Target names to exclude from task generation.

prefix

  • Type: 'directory' | 'none' | ((dir: string, target: string) => string)
  • Default: 'directory'

Task name prefix strategy.

  • 'directory': Use directory name as prefix (e.g. infra/docker-up)
  • 'none': No prefix (throws on name conflicts)
  • Function: (dir, target) => taskName for custom naming

cache

  • Type: boolean
  • Default: true

Enable caching for all generated tasks.

🚧 Limitations

  • Only .PHONY targets are converted to tasks
  • Variable expansion ($(VAR)) is not supported
  • Pattern rules (%.o: %.c) are not supported
  • Implicit rules are not supported
  • Recursive Make ($(MAKE) -C subdir) is not supported — use the include option instead
  • Conditional targets (ifeq / ifdef) are not supported

💖 Credit

This plugin is powered by:

Thank you! ❤️

©️ License

MIT

v0.3.3[beta]