vite-plugin-html-inject-commands
TypeScript icon, indicating that this package has built-in type declarations

0.1.3 • Public • Published

vite-plugin-html-inject-commands

npm version npm downloads bundle size codecov license

Inject commands result into index.html meta tag.

Installation

# ✨ 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

Usage

// 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',
        },
      ],
    }),
  ],
})

Type Declarations

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
}

Contribution

Local development
  • Clone this repository
  • Install the latest LTS version of Node.js
  • Enable Corepack using corepack enable
  • Install dependencies using pnpm install
  • Run tests using pnpm dev or pnpm test

License

Published under the MIT license. Made by @byronogis and community 💛


🤖 auto updated with automd (last updated: Mon Dec 30 2024)

Package Sidebar

Install

npm i vite-plugin-html-inject-commands

Weekly Downloads

1

Version

0.1.3

License

MIT

Unpacked Size

10 kB

Total Files

8

Last publish

Collaborators

  • byronogis