Skip to content

Trasformatori

Fornisce un'interfaccia unificata per trasformare il codice sorgente per supportare convenzioni.

ts
import { SourceCodeTransformer } from 'unocss'
import { createFilter } from 'unplugin-utils'

export default function myTransformers(options: MyOptions = {}): SourceCodeTransformer {
  return {
    name: 'my-transformer',
    enforce: 'pre', // applica prima di altri trasformatori
    idFilter(id) {
      // trasforma solo file .tsx e .jsx
      return id.match(/\.[tj]sx$/)
    },
    async transform(code, id, { uno }) {
      // code è un'istanza MagicString
      code.appendRight(0, '/* my transformer */')
    },
  }
}

Puoi controllare i trasformatori ufficiali per più esempi.

Released under the MIT License.