diff --git a/packages/plugin-react/package.json b/packages/plugin-react/package.json index 799de6c6f991f5..1603887e323fce 100644 --- a/packages/plugin-react/package.json +++ b/packages/plugin-react/package.json @@ -15,7 +15,7 @@ "scripts": { "dev": "tsc -p . -w --incremental", "build": "rimraf dist && run-s build-bundle build-types", - "build-bundle": "esbuild src/index.ts --bundle --platform=node --target=node12 --external:@babel/* --external:@rollup/* --external:resolve --external:react-refresh/* --outfile=dist/index.js", + "build-bundle": "esbuild src/index.ts --bundle --platform=node --target=node12 --external:@babel/* --external:@rollup/* --external:react-refresh/* --outfile=dist/index.js", "build-types": "tsc -p . --emitDeclarationOnly --outDir temp && api-extractor run && rimraf temp", "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . --lerna-package plugin-react", "release": "node ../../scripts/release.js --skipBuild" @@ -38,8 +38,7 @@ "@babel/plugin-transform-react-jsx-self": "^7.14.5", "@babel/plugin-transform-react-jsx-source": "^7.14.5", "@rollup/pluginutils": "^4.1.0", - "react-refresh": "^0.10.0", - "resolve": "^1.20.0" + "react-refresh": "^0.10.0" }, "devDependencies": { "vite": "link:../vite" diff --git a/packages/plugin-react/src/index.ts b/packages/plugin-react/src/index.ts index 752448e81e0b81..4765a880a93e1e 100644 --- a/packages/plugin-react/src/index.ts +++ b/packages/plugin-react/src/index.ts @@ -1,7 +1,6 @@ import type { ParserOptions, TransformOptions, types as t } from '@babel/core' import * as babel from '@babel/core' import { createFilter } from '@rollup/pluginutils' -import resolve from 'resolve' import type { Logger, Plugin, PluginOption } from 'vite' import { addRefreshWrapper, @@ -217,7 +216,7 @@ export default function viteReact(opts: Options = {}): PluginOption[] { config.plugins.forEach( (plugin) => (plugin.name === 'react-refresh' || - (plugin !== viteReactJsx && plugin.name === 'vite:react-jsx')) && + plugin.name === 'vite:react-jsx') && config.logger.warn( `[@vitejs/plugin-react] You should stop using "${plugin.name}" ` + `since this plugin conflicts with it.` @@ -246,43 +245,7 @@ export default function viteReact(opts: Options = {}): PluginOption[] { } } - const runtimeId = 'react/jsx-runtime' - // Adapted from https://github.com/alloc/vite-react-jsx - const viteReactJsx: Plugin = { - name: 'vite:react-jsx', - enforce: 'pre', - config: () => ({ - // react/jsx-runtime is in CJS format - // we want to explicitly cast it to ESM - optimizeDeps: { - include: ['react/jsx-runtime'] - } - }), - resolveId(id: string) { - return id === runtimeId ? id : null - }, - load(id: string) { - if (id === runtimeId) { - const runtimePath = resolve.sync(runtimeId, { - basedir: projectRoot - }) - const exports = ['jsx', 'jsxs', 'Fragment'] - return [ - `import * as jsxRuntime from '${runtimePath}'`, - // We can't use `export * from` or else any callsite that uses - // this module will be compiled to `jsxRuntime.exports.jsx` - // instead of the more concise `jsx` alias. - ...exports.map((name) => `export const ${name} = jsxRuntime.${name}`) - ].join('\n') - } - } - } - - return [ - viteBabel, - viteReactRefresh, - opts.jsxRuntime === 'automatic' && viteReactJsx - ] + return [viteBabel, viteReactRefresh] } viteReact.preambleCode = preambleCode