From 00b3e4fe102652b2d92e76a05e8c7a5b766b1d03 Mon Sep 17 00:00:00 2001 From: Tyler Rockwood Date: Tue, 12 Oct 2021 15:36:35 -0500 Subject: [PATCH] fix(plugin-react): fix regex for react imports (#5274) --- packages/plugin-react/src/index.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/plugin-react/src/index.ts b/packages/plugin-react/src/index.ts index 6d5f05aef8a32f..714d917e5ce81a 100644 --- a/packages/plugin-react/src/index.ts +++ b/packages/plugin-react/src/index.ts @@ -58,7 +58,11 @@ export default function viteReact(opts: Options = {}): PluginOption[] { const userParserPlugins = opts.parserPlugins || opts.babel?.parserOpts?.plugins || [] - const importReactRE = /(^|\n)import\s+(\*\s+as\s+)?React\s+/ + // Support pattens like: + // - import * as React from 'react'; + // - import React from 'react'; + // - import React, {useEffect} from 'react'; + const importReactRE = /(^|\n)import\s+(\*\s+as\s+)?React(,|\s+)/ const viteBabel: Plugin = { name: 'vite:react-babel',