@vitejs/plugin-react 2.0.0-alpha.3 → 2.0.0-beta.0
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 +20 -10
- package/dist/index.mjs +18 -8
- package/package.json +5 -6
- package/src/fast-refresh.ts +3 -3
- package/src/index.ts +16 -6
package/dist/index.cjs
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
const path = require('path');
|
3
|
+
const path = require('node:path');
|
4
4
|
const babel = require('@babel/core');
|
5
|
-
const pluginutils = require('@rollup/pluginutils');
|
6
5
|
const vite = require('vite');
|
7
|
-
const fs = require('fs');
|
8
|
-
const
|
6
|
+
const fs = require('node:fs');
|
7
|
+
const node_module = require('node:module');
|
9
8
|
|
10
9
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
11
10
|
|
@@ -26,7 +25,7 @@ const babel__namespace = /*#__PURE__*/_interopNamespace(babel);
|
|
26
25
|
const fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
27
26
|
|
28
27
|
const runtimePublicPath = "/@react-refresh";
|
29
|
-
const _require =
|
28
|
+
const _require = node_module.createRequire((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index.cjs', document.baseURI).href)));
|
30
29
|
const reactRefreshDir = path__default.dirname(_require.resolve("react-refresh/package.json"));
|
31
30
|
const runtimeFilePath = path__default.join(reactRefreshDir, "cjs/react-refresh-runtime.development.js");
|
32
31
|
const runtimeCode = `
|
@@ -185,9 +184,9 @@ function parseReactAlias(code) {
|
|
185
184
|
}
|
186
185
|
|
187
186
|
function viteReact(opts = {}) {
|
188
|
-
let
|
187
|
+
let devBase = "/";
|
189
188
|
let resolvedCacheDir;
|
190
|
-
let filter =
|
189
|
+
let filter = vite.createFilter(opts.include, opts.exclude);
|
191
190
|
let isProduction = true;
|
192
191
|
let projectRoot = process.cwd();
|
193
192
|
let skipFastRefresh = opts.fastRefresh === false;
|
@@ -200,11 +199,22 @@ function viteReact(opts = {}) {
|
|
200
199
|
const viteBabel = {
|
201
200
|
name: "vite:react-babel",
|
202
201
|
enforce: "pre",
|
202
|
+
config() {
|
203
|
+
if (opts.jsxRuntime === "classic") {
|
204
|
+
return {
|
205
|
+
esbuild: {
|
206
|
+
logOverride: {
|
207
|
+
"this-is-undefined-in-esm": "silent"
|
208
|
+
}
|
209
|
+
}
|
210
|
+
};
|
211
|
+
}
|
212
|
+
},
|
203
213
|
configResolved(config) {
|
204
|
-
|
214
|
+
devBase = config.base;
|
205
215
|
projectRoot = config.root;
|
206
216
|
resolvedCacheDir = vite.normalizePath(path__default.resolve(config.cacheDir));
|
207
|
-
filter =
|
217
|
+
filter = vite.createFilter(opts.include, opts.exclude, {
|
208
218
|
resolve: projectRoot
|
209
219
|
});
|
210
220
|
isProduction = config.isProduction;
|
@@ -367,7 +377,7 @@ function viteReact(opts = {}) {
|
|
367
377
|
{
|
368
378
|
tag: "script",
|
369
379
|
attrs: { type: "module" },
|
370
|
-
children: preambleCode.replace(`__BASE__`,
|
380
|
+
children: preambleCode.replace(`__BASE__`, devBase)
|
371
381
|
}
|
372
382
|
];
|
373
383
|
}
|
package/dist/index.mjs
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
import path from 'path';
|
1
|
+
import path from 'node:path';
|
2
2
|
import * as babel from '@babel/core';
|
3
|
-
import { createFilter } from '
|
4
|
-
import
|
5
|
-
import
|
6
|
-
import { createRequire } from 'module';
|
3
|
+
import { createFilter, normalizePath } from 'vite';
|
4
|
+
import fs from 'node:fs';
|
5
|
+
import { createRequire } from 'node:module';
|
7
6
|
|
8
7
|
const runtimePublicPath = "/@react-refresh";
|
9
8
|
const _require = createRequire(import.meta.url);
|
@@ -165,7 +164,7 @@ function parseReactAlias(code) {
|
|
165
164
|
}
|
166
165
|
|
167
166
|
function viteReact(opts = {}) {
|
168
|
-
let
|
167
|
+
let devBase = "/";
|
169
168
|
let resolvedCacheDir;
|
170
169
|
let filter = createFilter(opts.include, opts.exclude);
|
171
170
|
let isProduction = true;
|
@@ -180,8 +179,19 @@ function viteReact(opts = {}) {
|
|
180
179
|
const viteBabel = {
|
181
180
|
name: "vite:react-babel",
|
182
181
|
enforce: "pre",
|
182
|
+
config() {
|
183
|
+
if (opts.jsxRuntime === "classic") {
|
184
|
+
return {
|
185
|
+
esbuild: {
|
186
|
+
logOverride: {
|
187
|
+
"this-is-undefined-in-esm": "silent"
|
188
|
+
}
|
189
|
+
}
|
190
|
+
};
|
191
|
+
}
|
192
|
+
},
|
183
193
|
configResolved(config) {
|
184
|
-
|
194
|
+
devBase = config.base;
|
185
195
|
projectRoot = config.root;
|
186
196
|
resolvedCacheDir = normalizePath(path.resolve(config.cacheDir));
|
187
197
|
filter = createFilter(opts.include, opts.exclude, {
|
@@ -347,7 +357,7 @@ function viteReact(opts = {}) {
|
|
347
357
|
{
|
348
358
|
tag: "script",
|
349
359
|
attrs: { type: "module" },
|
350
|
-
children: preambleCode.replace(`__BASE__`,
|
360
|
+
children: preambleCode.replace(`__BASE__`, devBase)
|
351
361
|
}
|
352
362
|
];
|
353
363
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitejs/plugin-react",
|
3
|
-
"version": "2.0.0-
|
3
|
+
"version": "2.0.0-beta.0",
|
4
4
|
"license": "MIT",
|
5
5
|
"author": "Evan You",
|
6
6
|
"contributors": [
|
@@ -27,7 +27,7 @@
|
|
27
27
|
"prepublishOnly": "npm run build"
|
28
28
|
},
|
29
29
|
"engines": {
|
30
|
-
"node": ">=14.
|
30
|
+
"node": ">=14.18.0"
|
31
31
|
},
|
32
32
|
"repository": {
|
33
33
|
"type": "git",
|
@@ -39,16 +39,15 @@
|
|
39
39
|
},
|
40
40
|
"homepage": "https://github.com/vitejs/vite/tree/main/packages/plugin-react#readme",
|
41
41
|
"dependencies": {
|
42
|
-
"@babel/core": "^7.18.
|
42
|
+
"@babel/core": "^7.18.5",
|
43
43
|
"@babel/plugin-transform-react-jsx": "^7.17.12",
|
44
44
|
"@babel/plugin-transform-react-jsx-development": "^7.16.7",
|
45
45
|
"@babel/plugin-transform-react-jsx-self": "^7.17.12",
|
46
46
|
"@babel/plugin-transform-react-jsx-source": "^7.16.7",
|
47
|
-
"
|
48
|
-
"react-refresh": "^0.13.0"
|
47
|
+
"react-refresh": "^0.14.0"
|
49
48
|
},
|
50
49
|
"peerDependencies": {
|
51
|
-
"vite": "^3.0.0-alpha"
|
50
|
+
"vite": "^3.0.0-alpha.11"
|
52
51
|
},
|
53
52
|
"devDependencies": {
|
54
53
|
"vite": "workspace:*"
|
package/src/fast-refresh.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
import fs from 'fs'
|
2
|
-
import path from 'path'
|
3
|
-
import { createRequire } from 'module'
|
1
|
+
import fs from 'node:fs'
|
2
|
+
import path from 'node:path'
|
3
|
+
import { createRequire } from 'node:module'
|
4
4
|
import type { types as t } from '@babel/core'
|
5
5
|
|
6
6
|
export const runtimePublicPath = '/@react-refresh'
|
package/src/index.ts
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
import path from 'path'
|
1
|
+
import path from 'node:path'
|
2
2
|
import type { ParserOptions, TransformOptions, types as t } from '@babel/core'
|
3
3
|
import * as babel from '@babel/core'
|
4
|
-
import { createFilter } from '
|
5
|
-
import { normalizePath } from 'vite'
|
4
|
+
import { createFilter, normalizePath } from 'vite'
|
6
5
|
import type { Plugin, PluginOption, ResolvedConfig } from 'vite'
|
7
6
|
import {
|
8
7
|
addRefreshWrapper,
|
@@ -91,7 +90,7 @@ declare module 'vite' {
|
|
91
90
|
|
92
91
|
export default function viteReact(opts: Options = {}): PluginOption[] {
|
93
92
|
// Provide default values for Rollup compat.
|
94
|
-
let
|
93
|
+
let devBase = '/'
|
95
94
|
let resolvedCacheDir: string
|
96
95
|
let filter = createFilter(opts.include, opts.exclude)
|
97
96
|
let isProduction = true
|
@@ -118,8 +117,19 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
|
|
118
117
|
const viteBabel: Plugin = {
|
119
118
|
name: 'vite:react-babel',
|
120
119
|
enforce: 'pre',
|
120
|
+
config() {
|
121
|
+
if (opts.jsxRuntime === 'classic') {
|
122
|
+
return {
|
123
|
+
esbuild: {
|
124
|
+
logOverride: {
|
125
|
+
'this-is-undefined-in-esm': 'silent'
|
126
|
+
}
|
127
|
+
}
|
128
|
+
}
|
129
|
+
}
|
130
|
+
},
|
121
131
|
configResolved(config) {
|
122
|
-
|
132
|
+
devBase = config.base
|
123
133
|
projectRoot = config.root
|
124
134
|
resolvedCacheDir = normalizePath(path.resolve(config.cacheDir))
|
125
135
|
filter = createFilter(opts.include, opts.exclude, {
|
@@ -355,7 +365,7 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
|
|
355
365
|
{
|
356
366
|
tag: 'script',
|
357
367
|
attrs: { type: 'module' },
|
358
|
-
children: preambleCode.replace(`__BASE__`,
|
368
|
+
children: preambleCode.replace(`__BASE__`, devBase)
|
359
369
|
}
|
360
370
|
]
|
361
371
|
}
|