Refactor(files-util): Optimize the regular expression to match "import react"

This commit is contained in:
2024-10-26 15:47:40 +08:00
parent 9dff8897f1
commit 7608502d65

View File

@@ -106,7 +106,7 @@ export const cssToJs = (file: IFile) => {
}
export const addReactImport = (code: string) => {
if (!/import\s+React/g.test(code)) {
if (!/^\s*import\s+React\s+/g.test(code)) {
return `import React from 'react';\n${code}`
}
return code