Inject commands result into index.html meta tag.
# ✨ Auto-detect
npx nypm install -D vite-plugin-html-inject-commands
# npm
npm install -D vite-plugin-html-inject-commands
# yarn
yarn add -D vite-plugin-html-inject-commands
# pnpm
pnpm install -D vite-plugin-html-inject-commands
# bun
bun install -D vite-plugin-html-inject-commands
# deno
deno install --dev vite-plugin-html-inject-commands
// vite.config.ts
import { defineConfig } from 'vite'
import HTMLInjectCommands from 'vite-plugin-html-inject-commands'
export default defineConfig({
plugins: [
HTMLInjectCommands({
commands: [
/**
* Example: inject git commit hash and date to meta tag under head
* Result into head: `<meta name="git:commit" content="hash=123456, date=2021-09-01T00:00:00+00:00">`
*/
{
name: 'git:commit',
command: 'git log -1 --format="hash=%h, date=%aI"',
},
/**
* Example: a mistask command that will fail
* Result into head: `<meta name="git:commit" content="Failed to get commit info">`
*/
{
name: 'git:commit',
command: 'gitt log -1 --format="hash=%h, date=%aI"',
errorMsg: 'Failed to get commit info',
},
],
}),
],
})
export interface Options {
/**
* List of commands to be executed
*/
commands: Command[]
}
export interface Command {
/**
* Which will be used to name attribute of the meta tag
*/
name: string
/**
* Command to be executed
* The result of the command will be injected into content attribute of the meta tag
*/
command: string
/**
* Replease the content of the meta tag when the command fails
*/
errorMsg?: string
}
Local development
Published under the MIT license.
Made by @byronogis and community 💛
🤖 auto updated with automd (last updated: Mon Dec 30 2024)