mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-08 01:42:38 +00:00
29 lines
699 B
TypeScript
29 lines
699 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 = []
|
||
|
|
||
|
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
|
||
|
}
|