fix(ct): relax react import pattern (#14896)
This commit is contained in:
parent
1ed2e46f07
commit
59fa61aef1
|
|
@ -36,6 +36,7 @@ type CtConfig = {
|
||||||
ctViteConfig?: InlineConfig;
|
ctViteConfig?: InlineConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const importReactRE = /(^|\n)import\s+(\*\s+as\s+)?React(,|\s+)/;
|
||||||
|
|
||||||
export function createPlugin(
|
export function createPlugin(
|
||||||
registerSourceFile: string,
|
registerSourceFile: string,
|
||||||
|
|
@ -274,7 +275,7 @@ function vitePlugin(registerSource: string, relativeTemplateDir: string, buildIn
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vite React plugin will do this for .jsx files, but not .js files.
|
// Vite React plugin will do this for .jsx files, but not .js files.
|
||||||
if (id.endsWith('.js') && content.includes('React.createElement') && !content.includes('import React')) {
|
if (id.endsWith('.js') && content.includes('React.createElement') && !content.match(importReactRE)) {
|
||||||
const code = `import React from 'react';\n${content}`;
|
const code = `import React from 'react';\n${content}`;
|
||||||
return { code, map: { mappings: '' } };
|
return { code, map: { mappings: '' } };
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue