Skip to content

unplugin/unplugin-printer

Repository files navigation

unplugin-printer

unplugin-printer

Install

npm i unplugin-printer

Features

  • User-friendly options

  • Customizable styles

  • Supports async functions

Options

unplugin-printer uses kolorist and boxen to customize the text color and style of the output. You can refer to the documentation to explore the available options in detail.

import type * as kolorist from 'kolorist'

import type { Options as BoxenOptions } from 'boxen'

type Kolorist = typeof kolorist

type MessageValue = BoxenOptions & { text: string }

type Message = string | MessageValue | ((kolorist: Kolorist) => string | MessageValue | Promise<string | MessageValue | void>)

interface Options {
  info: Message[]
}

Usage

// vite.config.ts

import Printer from 'unplugin-printer/vite'

export default defineConfig({
  plugins: [
    Printer({
      info: [
        // 1. use string value
        'Hello World',

        // 2. use object to customize the style
        { text: 'Hello World', padding: 1, margin: 1, borderColor: 'green' },

        // 3. use function to customize the text color and style
        (kolorist) => {
          return {
            text: kolorist.yellow('Hello World'),
            padding: 1,
            margin: 1,
          }
        },

        // 4. use with async function
        async (kolorist) => {
          const text = await fetch('https://api.github.com/repos/unplugin/unplugin-printer')
            .then(res => res.json())
            .then(res => res.description)

          return {
            text: kolorist.yellow(text),
            padding: 1,
            margin: 1,
          }
        },
      ]
    }),
  ],
})
Vite
// vite.config.ts
import Printer from 'unplugin-printer/vite'

export default defineConfig({
  plugins: [
    Printer({ /* options */ }),
  ],
})


Webpack
// webpack.config.js
module.exports = {
  /* ... */
  plugins: [
    require('unplugin-printer/webpack')({ /* options */ })
  ]
}


Nuxt
// nuxt.config.js
export default defineNuxtConfig({
  modules: [
    ['unplugin-printer/nuxt', { /* options */ }],
  ],
})

This module works for both Nuxt 2 and Nuxt Vite


Vue CLI
// vue.config.js
module.exports = {
  configureWebpack: {
    plugins: [
      require('unplugin-printer/webpack')({ /* options */ }),
    ],
  },
}


License

MIT License © 2023-PRESENT webfansplz