@vitejs/plugin-react 3.0.0-alpha.0 → 3.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
+ const path = require('node:path');
3
4
  const babel = require('@babel/core');
4
5
  const vite = require('vite');
5
6
  const MagicString = require('magic-string');
6
7
  const fs = require('node:fs');
7
- const path = require('node:path');
8
8
  const node_module = require('node:module');
9
9
 
10
10
  function _interopNamespaceDefault(e) {
@@ -69,7 +69,7 @@ if (import.meta.hot) {
69
69
  RefreshRuntime.register(type, __SOURCE__ + " " + id)
70
70
  };
71
71
  window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
72
- }`.replace(/[\n]+/gm, "");
72
+ }`.replace(/\n+/g, "");
73
73
  const timeout = `
74
74
  if (!window.__vite_plugin_react_timeout) {
75
75
  window.__vite_plugin_react_timeout = setTimeout(() => {
@@ -163,12 +163,17 @@ function viteReact(opts = {}) {
163
163
  let runPluginOverrides = (options, context) => false;
164
164
  let staticBabelOptions;
165
165
  const useAutomaticRuntime = opts.jsxRuntime !== "classic";
166
- const importReactRE = /(^|\n)import\s+(\*\s+as\s+)?React(,|\s+)/;
167
- const fileExtensionRE = /\.[^\/\s\?]+$/;
166
+ const importReactRE = /(?:^|\n)import\s+(?:\*\s+as\s+)?React(?:,|\s+)/;
167
+ const fileExtensionRE = /\.[^/\s?]+$/;
168
168
  const viteBabel = {
169
169
  name: "vite:react-babel",
170
170
  enforce: "pre",
171
- config(_, { mode }) {
171
+ config(userConfig, { mode }) {
172
+ const resolvedRoot = vite.normalizePath(
173
+ userConfig.root ? path.resolve(userConfig.root) : process.cwd()
174
+ );
175
+ const envDir = userConfig.envDir ? vite.normalizePath(path.resolve(resolvedRoot, userConfig.envDir)) : resolvedRoot;
176
+ vite.loadEnv(mode, envDir, vite.resolveEnvPrefix(userConfig));
172
177
  const isProduction2 = (process.env.NODE_ENV || process.env.VITE_USER_NODE_ENV || mode) === "production";
173
178
  if (opts.jsxRuntime === "classic") {
174
179
  return {
@@ -231,7 +236,7 @@ function viteReact(opts = {}) {
231
236
  const ssr = options?.ssr === true;
232
237
  const [filepath, querystring = ""] = id.split("?");
233
238
  const [extension = ""] = querystring.match(fileExtensionRE) || filepath.match(fileExtensionRE) || [];
234
- if (/\.(mjs|[tj]sx?)$/.test(extension)) {
239
+ if (/\.(?:mjs|[tj]sx?)$/.test(extension)) {
235
240
  const isJSX = extension.endsWith("x");
236
241
  const isNodeModules = id.includes("/node_modules/");
237
242
  const isProjectFile = !isNodeModules && (id[0] === "\0" || id.startsWith(projectRoot + "/"));
@@ -412,8 +417,8 @@ function viteReact(opts = {}) {
412
417
  return [viteBabel, viteReactRefresh, useAutomaticRuntime && viteReactJsx];
413
418
  }
414
419
  viteReact.preambleCode = preambleCode;
415
- function loadPlugin(path) {
416
- return import(path).then((module) => module.default || module);
420
+ function loadPlugin(path2) {
421
+ return import(path2).then((module) => module.default || module);
417
422
  }
418
423
  function createBabelOptions(rawOptions) {
419
424
  var _a;
package/dist/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
+ import path from 'node:path';
1
2
  import * as babel from '@babel/core';
2
- import { createFilter } from 'vite';
3
+ import { createFilter, normalizePath, loadEnv, resolveEnvPrefix } from 'vite';
3
4
  import MagicString from 'magic-string';
4
5
  import fs from 'node:fs';
5
- import path from 'node:path';
6
6
  import { createRequire } from 'node:module';
7
7
 
8
8
  const runtimePublicPath = "/@react-refresh";
@@ -54,7 +54,7 @@ if (import.meta.hot) {
54
54
  RefreshRuntime.register(type, __SOURCE__ + " " + id)
55
55
  };
56
56
  window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
57
- }`.replace(/[\n]+/gm, "");
57
+ }`.replace(/\n+/g, "");
58
58
  const timeout = `
59
59
  if (!window.__vite_plugin_react_timeout) {
60
60
  window.__vite_plugin_react_timeout = setTimeout(() => {
@@ -148,12 +148,17 @@ function viteReact(opts = {}) {
148
148
  let runPluginOverrides = (options, context) => false;
149
149
  let staticBabelOptions;
150
150
  const useAutomaticRuntime = opts.jsxRuntime !== "classic";
151
- const importReactRE = /(^|\n)import\s+(\*\s+as\s+)?React(,|\s+)/;
152
- const fileExtensionRE = /\.[^\/\s\?]+$/;
151
+ const importReactRE = /(?:^|\n)import\s+(?:\*\s+as\s+)?React(?:,|\s+)/;
152
+ const fileExtensionRE = /\.[^/\s?]+$/;
153
153
  const viteBabel = {
154
154
  name: "vite:react-babel",
155
155
  enforce: "pre",
156
- config(_, { mode }) {
156
+ config(userConfig, { mode }) {
157
+ const resolvedRoot = normalizePath(
158
+ userConfig.root ? path.resolve(userConfig.root) : process.cwd()
159
+ );
160
+ const envDir = userConfig.envDir ? normalizePath(path.resolve(resolvedRoot, userConfig.envDir)) : resolvedRoot;
161
+ loadEnv(mode, envDir, resolveEnvPrefix(userConfig));
157
162
  const isProduction2 = (process.env.NODE_ENV || process.env.VITE_USER_NODE_ENV || mode) === "production";
158
163
  if (opts.jsxRuntime === "classic") {
159
164
  return {
@@ -216,7 +221,7 @@ function viteReact(opts = {}) {
216
221
  const ssr = options?.ssr === true;
217
222
  const [filepath, querystring = ""] = id.split("?");
218
223
  const [extension = ""] = querystring.match(fileExtensionRE) || filepath.match(fileExtensionRE) || [];
219
- if (/\.(mjs|[tj]sx?)$/.test(extension)) {
224
+ if (/\.(?:mjs|[tj]sx?)$/.test(extension)) {
220
225
  const isJSX = extension.endsWith("x");
221
226
  const isNodeModules = id.includes("/node_modules/");
222
227
  const isProjectFile = !isNodeModules && (id[0] === "\0" || id.startsWith(projectRoot + "/"));
@@ -397,8 +402,8 @@ function viteReact(opts = {}) {
397
402
  return [viteBabel, viteReactRefresh, useAutomaticRuntime && viteReactJsx];
398
403
  }
399
404
  viteReact.preambleCode = preambleCode;
400
- function loadPlugin(path) {
401
- return import(path).then((module) => module.default || module);
405
+ function loadPlugin(path2) {
406
+ return import(path2).then((module) => module.default || module);
402
407
  }
403
408
  function createBabelOptions(rawOptions) {
404
409
  var _a;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitejs/plugin-react",
3
- "version": "3.0.0-alpha.0",
3
+ "version": "3.0.0-alpha.1",
4
4
  "license": "MIT",
5
5
  "author": "Evan You",
6
6
  "contributors": [