Skip to content

Commit

Permalink
fix: import(/* @vite-ignore */) is not worked in *.ts for v4 (vitejs#…
Browse files Browse the repository at this point in the history
  • Loading branch information
moushicheng committed Dec 23, 2022
1 parent 568a014 commit a94b331
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/vite/src/node/plugins/esbuild.ts
Expand Up @@ -254,6 +254,14 @@ export function esbuildPlugin(options: ESBuildOptions = {}): Plugin {
},
async transform(code, id) {
if (filter(id) || filter(cleanUrl(id))) {
let hasViteIgnore = false
if (/\/\* @vite-ignore \*\//.test(code)) {
hasViteIgnore = true
code = code.replace(
/\s*\/\* @vite-ignore \*\/\s*/g,
'__vite__ignore__',
)
}
const result = await transformWithEsbuild(code, id, transformOptions)
if (result.warnings.length) {
result.warnings.forEach((m) => {
Expand All @@ -263,6 +271,12 @@ export function esbuildPlugin(options: ESBuildOptions = {}): Plugin {
if (options.jsxInject && /\.(?:j|t)sx\b/.test(id)) {
result.code = options.jsxInject + ';' + result.code
}
if (hasViteIgnore) {
result.code = result.code.replace(
/__vite__ignore__/,
'/* @vite-ignore */',
)
}
return {
code: result.code,
map: result.map,
Expand Down

0 comments on commit a94b331

Please sign in to comment.