unplugin-polish-tagged-templates
TypeScript icon, indicating that this package has built-in type declarations

0.2.1 • Public • Published

unplugin-polish-tagged-templates

NPM version Download monthly

Remove unnecessary tagged templates at compile time.

Features

  • 🦄 Unified plugin, support Vite/Rollup/Webpack/Nuxt/esbuild
  • 💎 polish class names tagged templates as preset
    • Support comment start with //
  • 🛠️ Custom tagged templates to polish

Only polish tagged templates in non-development environment.

Example

With the config:

polishTaggedTemplates({
  clsTags: ['cls'],
})

It will polish code from:

const className = cls`
  cursor-pointer
  font-bold text-xl
  // comment here
  text-sky-500
  hover:text-sky-600
`

function Component() {
  return (
    <p
      className={cls`
        cursor-pointer
        font-bold text-xl
        // comment here
        text-sky-500
        hover:text-sky-600
      `}
      // ...
    >
      Hi
    </p>
  )
}

to

const className = 'cursor-pointer font-bold text-xl text-sky-500 hover:text-sky-600'

function Component() {
  return (
    <p
      className='cursor-pointer font-bold text-xl text-sky-500 hover:text-sky-600'
      // ...
    >
      Hi
    </p>
  )
}

However, there is no effect if tagged templates has any expressions.

This plugin make you free to use tagged templates to composite class name or others aims, and remove unnecessary tagged templates at compile time.

[!TIP] For better compile performance, you'd better reduce using nested tagged templates as much as possible.

Install

npm i unplugin-polish-tagged-templates
Vite
// vite.config.ts
import polishTaggedTemplates from 'unplugin-polish-tagged-templates/vite'

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

Example: playground/


Rollup
// rollup.config.js
import polishTaggedTemplates from 'unplugin-polish-tagged-templates/rollup'

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


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


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

This module works for both Nuxt 2 and Nuxt Vite


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


esbuild
// esbuild.config.js
import { build } from 'esbuild'
import polishTaggedTemplates from 'unplugin-polish-tagged-templates/esbuild'

build({
  plugins: [polishTaggedTemplates()],
})


Related

/unplugin-polish-tagged-templates/

    Package Sidebar

    Install

    npm i unplugin-polish-tagged-templates

    Weekly Downloads

    262

    Version

    0.2.1

    License

    MIT

    Unpacked Size

    75.1 kB

    Total Files

    44

    Last publish

    Collaborators

    • theprimone