This repository has been archived by the owner on Apr 6, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vite): support
build.transpile
as function (#7767)
Co-authored-by: Daniel Roe <daniel@roe.dev>
- Loading branch information
Showing
6 changed files
with
43 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters