mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-01 00:00:29 +00:00
29 lines
709 B
TypeScript
29 lines
709 B
TypeScript
import { useNuxt } from '@nuxt/kit'
|
|
import escapeRegExp from 'escape-string-regexp'
|
|
import { normalize } from 'pathe'
|
|
|
|
interface Envs {
|
|
isDev: boolean
|
|
isClient?: boolean
|
|
isServer?: boolean
|
|
}
|
|
|
|
export function transpile (envs: Envs): Array<string | RegExp> {
|
|
const nuxt = useNuxt()
|
|
const transpile: RegExp[] = []
|
|
|
|
for (let pattern of nuxt.options.build.transpile) {
|
|
if (typeof pattern === 'function') {
|
|
const result = pattern(envs)
|
|
if (result) { pattern = result }
|
|
}
|
|
if (typeof pattern === 'string') {
|
|
transpile.push(new RegExp(escapeRegExp(normalize(pattern))))
|
|
} else if (pattern instanceof RegExp) {
|
|
transpile.push(pattern)
|
|
}
|
|
}
|
|
|
|
return transpile
|
|
}
|