v1.0 with SW PWA enabled
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019-present, Yuxi (Evan) You and Vite contributors
|
||||
Copyright (c) Arnaud Barré (https://github.com/ArnaudBarre)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
134
frontend/node_modules/@vitejs/plugin-react-swc/README.md
generated
vendored
Normal file
134
frontend/node_modules/@vitejs/plugin-react-swc/README.md
generated
vendored
Normal file
@ -0,0 +1,134 @@
|
||||
# @vitejs/plugin-react-swc [](https://www.npmjs.com/package/@vitejs/plugin-react-swc)
|
||||
|
||||
Speed up your Vite dev server with [SWC](https://swc.rs/)
|
||||
|
||||
- ✅ A fast Fast Refresh (~20x faster than Babel)
|
||||
- ✅ Enable [automatic JSX runtime](https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html)
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
npm i -D @vitejs/plugin-react-swc
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```ts
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react-swc'
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
})
|
||||
```
|
||||
|
||||
## Caveats
|
||||
|
||||
This plugin has limited options to enable good performances and be transpiler agnostic. Here is the list of non-configurable options that impact runtime behaviour:
|
||||
|
||||
- [useDefineForClassFields](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#the-usedefineforclassfields-flag-and-the-declare-property-modifier) is always activated, as this matches the current ECMAScript spec
|
||||
- `jsx runtime` is always `automatic`
|
||||
- In development:
|
||||
- esbuild is disabled, so the [esbuild configuration](https://vite.dev/config/shared-options.html#esbuild) has no effect
|
||||
- `target` is ignored and defaults to `es2020` (see [`devTarget`](#devtarget))
|
||||
- JS files are not transformed
|
||||
- tsconfig is not resolved, so properties other than the ones listed above behaves like TS defaults
|
||||
|
||||
## Options
|
||||
|
||||
### jsxImportSource
|
||||
|
||||
Control where the JSX factory is imported from.
|
||||
|
||||
`@default` "react"
|
||||
|
||||
```ts
|
||||
react({ jsxImportSource: '@emotion/react' })
|
||||
```
|
||||
|
||||
### tsDecorators
|
||||
|
||||
Enable TypeScript decorators. Requires `experimentalDecorators` in tsconfig.
|
||||
|
||||
`@default` false
|
||||
|
||||
```ts
|
||||
react({ tsDecorators: true })
|
||||
```
|
||||
|
||||
### plugins
|
||||
|
||||
Use SWC plugins. Enable SWC at build time.
|
||||
|
||||
```ts
|
||||
react({ plugins: [['@swc/plugin-styled-components', {}]] })
|
||||
```
|
||||
|
||||
### devTarget
|
||||
|
||||
Set the target for SWC in dev. This can avoid to down-transpile private class method for example.
|
||||
|
||||
For production target, see https://vite.dev/config/build-options.html#build-target.
|
||||
|
||||
`@default` "es2020"
|
||||
|
||||
```ts
|
||||
react({ devTarget: 'es2022' })
|
||||
```
|
||||
|
||||
### parserConfig
|
||||
|
||||
Override the default include list (.ts, .tsx, .mts, .jsx, .mdx).
|
||||
|
||||
This requires to redefine the config for any file you want to be included (ts, mdx, ...).
|
||||
|
||||
If you want to trigger fast refresh on compiled JS, use `jsx: true`. Exclusion of node_modules should be handled by the function if needed. Using this option to use JSX inside `.js` files is highly discouraged and can be removed in any future version.
|
||||
|
||||
```ts
|
||||
react({
|
||||
parserConfig(id) {
|
||||
if (id.endsWith('.res')) return { syntax: 'ecmascript', jsx: true }
|
||||
if (id.endsWith('.ts')) return { syntax: 'typescript', tsx: false }
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
### reactRefreshHost
|
||||
|
||||
The `reactRefreshHost` option is only necessary in a module federation context. It enables HMR to work between a remote & host application. In your remote Vite config, you would add your host origin:
|
||||
|
||||
```js
|
||||
react({ reactRefreshHost: 'http://localhost:3000' })
|
||||
```
|
||||
|
||||
Under the hood, this simply updates the React Fash Refresh runtime URL from `/@react-refresh` to `http://localhost:3000/@react-refresh` to ensure there is only one Refresh runtime across the whole application. Note that if you define `base` option in the host application, you need to include it in the option, like: `http://localhost:3000/{base}`.
|
||||
|
||||
### useAtYourOwnRisk_mutateSwcOptions
|
||||
|
||||
The future of Vite is with OXC, and from the beginning this was a design choice to not exposed too many specialties from SWC so that Vite React users can move to another transformer later.
|
||||
Also debugging why some specific version of decorators with some other unstable/legacy feature doesn't work is not fun, so we won't provide support for it, hence the name `useAtYourOwnRisk`.
|
||||
|
||||
```ts
|
||||
react({
|
||||
useAtYourOwnRisk_mutateSwcOptions(options) {
|
||||
options.jsc.parser.decorators = true
|
||||
options.jsc.transform.decoratorVersion = '2022-03'
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
### disableOxcRecommendation
|
||||
|
||||
If set, disables the recommendation to use `@vitejs/plugin-react-oxc` (which is shown when `rolldown-vite` is detected and neither `swc` plugins are used nor the `swc` options are mutated).
|
||||
|
||||
```ts
|
||||
react({ disableOxcRecommendation: true })
|
||||
```
|
||||
|
||||
## Consistent components exports
|
||||
|
||||
For React refresh to work correctly, your file should only export React components. The best explanation I've read is the one from the [Gatsby docs](https://www.gatsbyjs.com/docs/reference/local-development/fast-refresh/#how-it-works).
|
||||
|
||||
If an incompatible change in exports is found, the module will be invalidated and HMR will propagate. To make it easier to export simple constants alongside your component, the module is only invalidated when their value changes.
|
||||
|
||||
You can catch mistakes and get more detailed warning with this [eslint rule](https://github.com/ArnaudBarre/eslint-plugin-react-refresh).
|
||||
262
frontend/node_modules/@vitejs/plugin-react-swc/index.cjs
generated
vendored
Normal file
262
frontend/node_modules/@vitejs/plugin-react-swc/index.cjs
generated
vendored
Normal file
@ -0,0 +1,262 @@
|
||||
//#region rolldown:runtime
|
||||
var __create = Object.create;
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __getProtoOf = Object.getPrototypeOf;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
||||
key = keys[i];
|
||||
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
||||
get: ((k) => from[k]).bind(null, key),
|
||||
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
||||
});
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
||||
value: mod,
|
||||
enumerable: true
|
||||
}) : target, mod));
|
||||
|
||||
//#endregion
|
||||
const node_fs = __toESM(require("node:fs"));
|
||||
const node_path = __toESM(require("node:path"));
|
||||
const node_url = __toESM(require("node:url"));
|
||||
const node_module = __toESM(require("node:module"));
|
||||
const __swc_core = __toESM(require("@swc/core"));
|
||||
const vite = __toESM(require("vite"));
|
||||
const __rolldown_pluginutils = __toESM(require("@rolldown/pluginutils"));
|
||||
|
||||
//#region ../common/refresh-utils.ts
|
||||
const runtimePublicPath = "/@react-refresh";
|
||||
const reactCompRE = /extends\s+(?:React\.)?(?:Pure)?Component/;
|
||||
const refreshContentRE = /\$RefreshReg\$\(/;
|
||||
const preambleCode = `import { injectIntoGlobalHook } from "__BASE__${runtimePublicPath.slice(1)}";
|
||||
injectIntoGlobalHook(window);
|
||||
window.$RefreshReg$ = () => {};
|
||||
window.$RefreshSig$ = () => (type) => type;`;
|
||||
const getPreambleCode = (base) => preambleCode.replace("__BASE__", base);
|
||||
const avoidSourceMapOption = Symbol();
|
||||
function addRefreshWrapper(code, map, pluginName, id, reactRefreshHost = "") {
|
||||
const hasRefresh = refreshContentRE.test(code);
|
||||
const onlyReactComp = !hasRefresh && reactCompRE.test(code);
|
||||
const normalizedMap = map === avoidSourceMapOption ? null : map;
|
||||
if (!hasRefresh && !onlyReactComp) return {
|
||||
code,
|
||||
map: normalizedMap
|
||||
};
|
||||
const avoidSourceMap = map === avoidSourceMapOption;
|
||||
const newMap = typeof normalizedMap === "string" ? JSON.parse(normalizedMap) : normalizedMap;
|
||||
let newCode = code;
|
||||
if (hasRefresh) {
|
||||
const refreshHead = removeLineBreaksIfNeeded(`let prevRefreshReg;
|
||||
let prevRefreshSig;
|
||||
|
||||
if (import.meta.hot && !inWebWorker) {
|
||||
if (!window.$RefreshReg$) {
|
||||
throw new Error(
|
||||
"${pluginName} can't detect preamble. Something is wrong."
|
||||
);
|
||||
}
|
||||
|
||||
prevRefreshReg = window.$RefreshReg$;
|
||||
prevRefreshSig = window.$RefreshSig$;
|
||||
window.$RefreshReg$ = RefreshRuntime.getRefreshReg(${JSON.stringify(id)});
|
||||
window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
|
||||
}
|
||||
|
||||
`, avoidSourceMap);
|
||||
newCode = `${refreshHead}${newCode}
|
||||
|
||||
if (import.meta.hot && !inWebWorker) {
|
||||
window.$RefreshReg$ = prevRefreshReg;
|
||||
window.$RefreshSig$ = prevRefreshSig;
|
||||
}
|
||||
`;
|
||||
if (newMap) newMap.mappings = ";".repeat(16) + newMap.mappings;
|
||||
}
|
||||
const sharedHead = removeLineBreaksIfNeeded(`import * as RefreshRuntime from "${reactRefreshHost}${runtimePublicPath}";
|
||||
const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
|
||||
|
||||
`, avoidSourceMap);
|
||||
newCode = `${sharedHead}${newCode}
|
||||
|
||||
if (import.meta.hot && !inWebWorker) {
|
||||
RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
|
||||
RefreshRuntime.registerExportsForReactRefresh(${JSON.stringify(id)}, currentExports);
|
||||
import.meta.hot.accept((nextExports) => {
|
||||
if (!nextExports) return;
|
||||
const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate(${JSON.stringify(id)}, currentExports, nextExports);
|
||||
if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
|
||||
});
|
||||
});
|
||||
}
|
||||
`;
|
||||
if (newMap) newMap.mappings = ";;;" + newMap.mappings;
|
||||
return {
|
||||
code: newCode,
|
||||
map: newMap
|
||||
};
|
||||
}
|
||||
function removeLineBreaksIfNeeded(code, enabled) {
|
||||
return enabled ? code.replace(/\n/g, "") : code;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region ../common/warning.ts
|
||||
const silenceUseClientWarning = (userConfig) => ({ rollupOptions: { onwarn(warning, defaultHandler) {
|
||||
if (warning.code === "MODULE_LEVEL_DIRECTIVE" && (warning.message.includes("use client") || warning.message.includes("use server"))) return;
|
||||
if (warning.code === "SOURCEMAP_ERROR" && warning.message.includes("resolve original location") && warning.pos === 0) return;
|
||||
if (userConfig.build?.rollupOptions?.onwarn) userConfig.build.rollupOptions.onwarn(warning, defaultHandler);
|
||||
else defaultHandler(warning);
|
||||
} } });
|
||||
|
||||
//#endregion
|
||||
//#region src/index.ts
|
||||
const _dirname = typeof __dirname !== "undefined" ? __dirname : (0, node_path.dirname)((0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href));
|
||||
const resolve = (0, node_module.createRequire)(typeof __filename !== "undefined" ? __filename : require("url").pathToFileURL(__filename).href).resolve;
|
||||
const react = (_options) => {
|
||||
let hmrDisabled = false;
|
||||
const options = {
|
||||
jsxImportSource: _options?.jsxImportSource ?? "react",
|
||||
tsDecorators: _options?.tsDecorators,
|
||||
plugins: _options?.plugins ? _options?.plugins.map((el) => [resolve(el[0]), el[1]]) : void 0,
|
||||
devTarget: _options?.devTarget ?? "es2020",
|
||||
parserConfig: _options?.parserConfig,
|
||||
reactRefreshHost: _options?.reactRefreshHost,
|
||||
useAtYourOwnRisk_mutateSwcOptions: _options?.useAtYourOwnRisk_mutateSwcOptions,
|
||||
disableOxcRecommendation: _options?.disableOxcRecommendation
|
||||
};
|
||||
return [
|
||||
{
|
||||
name: "vite:react-swc:resolve-runtime",
|
||||
apply: "serve",
|
||||
enforce: "pre",
|
||||
resolveId: {
|
||||
filter: { id: (0, __rolldown_pluginutils.exactRegex)(runtimePublicPath) },
|
||||
handler: (id) => id === runtimePublicPath ? id : void 0
|
||||
},
|
||||
load: {
|
||||
filter: { id: (0, __rolldown_pluginutils.exactRegex)(runtimePublicPath) },
|
||||
handler: (id) => id === runtimePublicPath ? (0, node_fs.readFileSync)((0, node_path.join)(_dirname, "refresh-runtime.js"), "utf-8").replace(/__README_URL__/g, "https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react-swc") : void 0
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "vite:react-swc",
|
||||
apply: "serve",
|
||||
config: () => ({
|
||||
esbuild: false,
|
||||
oxc: false,
|
||||
optimizeDeps: {
|
||||
include: [`${options.jsxImportSource}/jsx-dev-runtime`],
|
||||
..."rolldownVersion" in vite ? { rollupOptions: { jsx: { mode: "automatic" } } } : { esbuildOptions: { jsx: "automatic" } }
|
||||
}
|
||||
}),
|
||||
configResolved(config) {
|
||||
if (config.server.hmr === false) hmrDisabled = true;
|
||||
const mdxIndex = config.plugins.findIndex((p) => p.name === "@mdx-js/rollup");
|
||||
if (mdxIndex !== -1 && mdxIndex > config.plugins.findIndex((p) => p.name === "vite:react-swc")) throw new Error("[vite:react-swc] The MDX plugin should be placed before this plugin");
|
||||
if ("rolldownVersion" in vite && !options.plugins && !options.useAtYourOwnRisk_mutateSwcOptions && !options.disableOxcRecommendation) config.logger.warn("[vite:react-swc] We recommend switching to `@vitejs/plugin-react-oxc` for improved performance as no swc plugins are used. More information at https://vite.dev/rolldown");
|
||||
},
|
||||
transformIndexHtml: (_, config) => {
|
||||
if (!hmrDisabled) return [{
|
||||
tag: "script",
|
||||
attrs: { type: "module" },
|
||||
children: getPreambleCode(config.server.config.base)
|
||||
}];
|
||||
},
|
||||
async transform(code, _id, transformOptions) {
|
||||
const id = _id.split("?")[0];
|
||||
const refresh = !transformOptions?.ssr && !hmrDisabled;
|
||||
const result = await transformWithOptions(id, code, options.devTarget, options, {
|
||||
refresh,
|
||||
development: true,
|
||||
runtime: "automatic",
|
||||
importSource: options.jsxImportSource
|
||||
});
|
||||
if (!result) return;
|
||||
if (!refresh) return result;
|
||||
return addRefreshWrapper(result.code, result.map, "@vitejs/plugin-react-swc", id, options.reactRefreshHost);
|
||||
}
|
||||
},
|
||||
options.plugins ? {
|
||||
name: "vite:react-swc",
|
||||
apply: "build",
|
||||
enforce: "pre",
|
||||
config: (userConfig) => ({ build: silenceUseClientWarning(userConfig) }),
|
||||
transform: (code, _id) => transformWithOptions(_id.split("?")[0], code, "esnext", options, {
|
||||
runtime: "automatic",
|
||||
importSource: options.jsxImportSource
|
||||
})
|
||||
} : {
|
||||
name: "vite:react-swc",
|
||||
apply: "build",
|
||||
config: (userConfig) => ({
|
||||
build: silenceUseClientWarning(userConfig),
|
||||
esbuild: {
|
||||
jsx: "automatic",
|
||||
jsxImportSource: options.jsxImportSource,
|
||||
tsconfigRaw: { compilerOptions: { useDefineForClassFields: true } }
|
||||
}
|
||||
})
|
||||
}
|
||||
];
|
||||
};
|
||||
const transformWithOptions = async (id, code, target, options, reactConfig) => {
|
||||
const decorators = options?.tsDecorators ?? false;
|
||||
const parser = options.parserConfig ? options.parserConfig(id) : id.endsWith(".tsx") ? {
|
||||
syntax: "typescript",
|
||||
tsx: true,
|
||||
decorators
|
||||
} : id.endsWith(".ts") || id.endsWith(".mts") ? {
|
||||
syntax: "typescript",
|
||||
tsx: false,
|
||||
decorators
|
||||
} : id.endsWith(".jsx") ? {
|
||||
syntax: "ecmascript",
|
||||
jsx: true
|
||||
} : id.endsWith(".mdx") ? {
|
||||
syntax: "ecmascript",
|
||||
jsx: true
|
||||
} : void 0;
|
||||
if (!parser) return;
|
||||
let result;
|
||||
try {
|
||||
const swcOptions = {
|
||||
filename: id,
|
||||
swcrc: false,
|
||||
configFile: false,
|
||||
sourceMaps: true,
|
||||
jsc: {
|
||||
target,
|
||||
parser,
|
||||
experimental: { plugins: options.plugins },
|
||||
transform: {
|
||||
useDefineForClassFields: true,
|
||||
react: reactConfig
|
||||
}
|
||||
}
|
||||
};
|
||||
if (options.useAtYourOwnRisk_mutateSwcOptions) options.useAtYourOwnRisk_mutateSwcOptions(swcOptions);
|
||||
result = await (0, __swc_core.transform)(code, swcOptions);
|
||||
} catch (e) {
|
||||
const message = e.message;
|
||||
const fileStartIndex = message.indexOf("╭─[");
|
||||
if (fileStartIndex !== -1) {
|
||||
const match = message.slice(fileStartIndex).match(/:(\d+):(\d+)\]/);
|
||||
if (match) {
|
||||
e.line = match[1];
|
||||
e.column = match[2];
|
||||
}
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return result;
|
||||
};
|
||||
var src_default = react;
|
||||
|
||||
//#endregion
|
||||
module.exports = src_default;
|
||||
module.exports.default = module.exports
|
||||
57
frontend/node_modules/@vitejs/plugin-react-swc/index.d.cts
generated
vendored
Normal file
57
frontend/node_modules/@vitejs/plugin-react-swc/index.d.cts
generated
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
import { JscTarget, Options, ParserConfig } from "@swc/core";
|
||||
import { Plugin } from "vite";
|
||||
|
||||
//#region src/index.d.ts
|
||||
type Options$1 = {
|
||||
/**
|
||||
* Control where the JSX factory is imported from.
|
||||
* @default "react"
|
||||
*/
|
||||
jsxImportSource?: string;
|
||||
/**
|
||||
* Enable TypeScript decorators. Requires experimentalDecorators in tsconfig.
|
||||
* @default false
|
||||
*/
|
||||
tsDecorators?: boolean;
|
||||
/**
|
||||
* Use SWC plugins. Enable SWC at build time.
|
||||
* @default undefined
|
||||
*/
|
||||
plugins?: [string, Record<string, any>][];
|
||||
/**
|
||||
* Set the target for SWC in dev. This can avoid to down-transpile private class method for example.
|
||||
* For production target, see https://vite.dev/config/build-options.html#build-target
|
||||
* @default "es2020"
|
||||
*/
|
||||
devTarget?: JscTarget;
|
||||
/**
|
||||
* Override the default include list (.ts, .tsx, .mts, .jsx, .mdx).
|
||||
* This requires to redefine the config for any file you want to be included.
|
||||
* If you want to trigger fast refresh on compiled JS, use `jsx: true`.
|
||||
* Exclusion of node_modules should be handled by the function if needed.
|
||||
*/
|
||||
parserConfig?: (id: string) => ParserConfig | undefined;
|
||||
/**
|
||||
* React Fast Refresh runtime URL prefix.
|
||||
* Useful in a module federation context to enable HMR by specifying
|
||||
* the host application URL in a Vite config of a remote application.
|
||||
* @example
|
||||
* reactRefreshHost: 'http://localhost:3000'
|
||||
*/
|
||||
reactRefreshHost?: string;
|
||||
/**
|
||||
* The future of Vite is with OXC, and from the beginning this was a design choice
|
||||
* to not exposed too many specialties from SWC so that Vite React users can move to
|
||||
* another transformer later.
|
||||
* Also debugging why some specific version of decorators with some other unstable/legacy
|
||||
* feature doesn't work is not fun, so we won't provide support for it, hence the name `useAtYourOwnRisk`
|
||||
*/
|
||||
useAtYourOwnRisk_mutateSwcOptions?: (options: Options) => void;
|
||||
/**
|
||||
* If set, disables the recommendation to use `@vitejs/plugin-react-oxc`
|
||||
*/
|
||||
disableOxcRecommendation?: boolean;
|
||||
};
|
||||
declare const react: (_options?: Options$1) => Plugin[];
|
||||
//#endregion
|
||||
export { react as default };
|
||||
57
frontend/node_modules/@vitejs/plugin-react-swc/index.d.ts
generated
vendored
Normal file
57
frontend/node_modules/@vitejs/plugin-react-swc/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
import { JscTarget, Options, ParserConfig } from "@swc/core";
|
||||
import { Plugin } from "vite";
|
||||
|
||||
//#region src/index.d.ts
|
||||
type Options$1 = {
|
||||
/**
|
||||
* Control where the JSX factory is imported from.
|
||||
* @default "react"
|
||||
*/
|
||||
jsxImportSource?: string;
|
||||
/**
|
||||
* Enable TypeScript decorators. Requires experimentalDecorators in tsconfig.
|
||||
* @default false
|
||||
*/
|
||||
tsDecorators?: boolean;
|
||||
/**
|
||||
* Use SWC plugins. Enable SWC at build time.
|
||||
* @default undefined
|
||||
*/
|
||||
plugins?: [string, Record<string, any>][];
|
||||
/**
|
||||
* Set the target for SWC in dev. This can avoid to down-transpile private class method for example.
|
||||
* For production target, see https://vite.dev/config/build-options.html#build-target
|
||||
* @default "es2020"
|
||||
*/
|
||||
devTarget?: JscTarget;
|
||||
/**
|
||||
* Override the default include list (.ts, .tsx, .mts, .jsx, .mdx).
|
||||
* This requires to redefine the config for any file you want to be included.
|
||||
* If you want to trigger fast refresh on compiled JS, use `jsx: true`.
|
||||
* Exclusion of node_modules should be handled by the function if needed.
|
||||
*/
|
||||
parserConfig?: (id: string) => ParserConfig | undefined;
|
||||
/**
|
||||
* React Fast Refresh runtime URL prefix.
|
||||
* Useful in a module federation context to enable HMR by specifying
|
||||
* the host application URL in a Vite config of a remote application.
|
||||
* @example
|
||||
* reactRefreshHost: 'http://localhost:3000'
|
||||
*/
|
||||
reactRefreshHost?: string;
|
||||
/**
|
||||
* The future of Vite is with OXC, and from the beginning this was a design choice
|
||||
* to not exposed too many specialties from SWC so that Vite React users can move to
|
||||
* another transformer later.
|
||||
* Also debugging why some specific version of decorators with some other unstable/legacy
|
||||
* feature doesn't work is not fun, so we won't provide support for it, hence the name `useAtYourOwnRisk`
|
||||
*/
|
||||
useAtYourOwnRisk_mutateSwcOptions?: (options: Options) => void;
|
||||
/**
|
||||
* If set, disables the recommendation to use `@vitejs/plugin-react-oxc`
|
||||
*/
|
||||
disableOxcRecommendation?: boolean;
|
||||
};
|
||||
declare const react: (_options?: Options$1) => Plugin[];
|
||||
//#endregion
|
||||
export { react as default };
|
||||
238
frontend/node_modules/@vitejs/plugin-react-swc/index.js
generated
vendored
Normal file
238
frontend/node_modules/@vitejs/plugin-react-swc/index.js
generated
vendored
Normal file
@ -0,0 +1,238 @@
|
||||
import { createRequire } from "node:module";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { dirname, join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { transform } from "@swc/core";
|
||||
import * as vite from "vite";
|
||||
import { exactRegex } from "@rolldown/pluginutils";
|
||||
|
||||
//#region ../common/refresh-utils.ts
|
||||
const runtimePublicPath = "/@react-refresh";
|
||||
const reactCompRE = /extends\s+(?:React\.)?(?:Pure)?Component/;
|
||||
const refreshContentRE = /\$RefreshReg\$\(/;
|
||||
const preambleCode = `import { injectIntoGlobalHook } from "__BASE__${runtimePublicPath.slice(1)}";
|
||||
injectIntoGlobalHook(window);
|
||||
window.$RefreshReg$ = () => {};
|
||||
window.$RefreshSig$ = () => (type) => type;`;
|
||||
const getPreambleCode = (base) => preambleCode.replace("__BASE__", base);
|
||||
const avoidSourceMapOption = Symbol();
|
||||
function addRefreshWrapper(code, map, pluginName, id, reactRefreshHost = "") {
|
||||
const hasRefresh = refreshContentRE.test(code);
|
||||
const onlyReactComp = !hasRefresh && reactCompRE.test(code);
|
||||
const normalizedMap = map === avoidSourceMapOption ? null : map;
|
||||
if (!hasRefresh && !onlyReactComp) return {
|
||||
code,
|
||||
map: normalizedMap
|
||||
};
|
||||
const avoidSourceMap = map === avoidSourceMapOption;
|
||||
const newMap = typeof normalizedMap === "string" ? JSON.parse(normalizedMap) : normalizedMap;
|
||||
let newCode = code;
|
||||
if (hasRefresh) {
|
||||
const refreshHead = removeLineBreaksIfNeeded(`let prevRefreshReg;
|
||||
let prevRefreshSig;
|
||||
|
||||
if (import.meta.hot && !inWebWorker) {
|
||||
if (!window.$RefreshReg$) {
|
||||
throw new Error(
|
||||
"${pluginName} can't detect preamble. Something is wrong."
|
||||
);
|
||||
}
|
||||
|
||||
prevRefreshReg = window.$RefreshReg$;
|
||||
prevRefreshSig = window.$RefreshSig$;
|
||||
window.$RefreshReg$ = RefreshRuntime.getRefreshReg(${JSON.stringify(id)});
|
||||
window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
|
||||
}
|
||||
|
||||
`, avoidSourceMap);
|
||||
newCode = `${refreshHead}${newCode}
|
||||
|
||||
if (import.meta.hot && !inWebWorker) {
|
||||
window.$RefreshReg$ = prevRefreshReg;
|
||||
window.$RefreshSig$ = prevRefreshSig;
|
||||
}
|
||||
`;
|
||||
if (newMap) newMap.mappings = ";".repeat(16) + newMap.mappings;
|
||||
}
|
||||
const sharedHead = removeLineBreaksIfNeeded(`import * as RefreshRuntime from "${reactRefreshHost}${runtimePublicPath}";
|
||||
const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
|
||||
|
||||
`, avoidSourceMap);
|
||||
newCode = `${sharedHead}${newCode}
|
||||
|
||||
if (import.meta.hot && !inWebWorker) {
|
||||
RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
|
||||
RefreshRuntime.registerExportsForReactRefresh(${JSON.stringify(id)}, currentExports);
|
||||
import.meta.hot.accept((nextExports) => {
|
||||
if (!nextExports) return;
|
||||
const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate(${JSON.stringify(id)}, currentExports, nextExports);
|
||||
if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
|
||||
});
|
||||
});
|
||||
}
|
||||
`;
|
||||
if (newMap) newMap.mappings = ";;;" + newMap.mappings;
|
||||
return {
|
||||
code: newCode,
|
||||
map: newMap
|
||||
};
|
||||
}
|
||||
function removeLineBreaksIfNeeded(code, enabled) {
|
||||
return enabled ? code.replace(/\n/g, "") : code;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region ../common/warning.ts
|
||||
const silenceUseClientWarning = (userConfig) => ({ rollupOptions: { onwarn(warning, defaultHandler) {
|
||||
if (warning.code === "MODULE_LEVEL_DIRECTIVE" && (warning.message.includes("use client") || warning.message.includes("use server"))) return;
|
||||
if (warning.code === "SOURCEMAP_ERROR" && warning.message.includes("resolve original location") && warning.pos === 0) return;
|
||||
if (userConfig.build?.rollupOptions?.onwarn) userConfig.build.rollupOptions.onwarn(warning, defaultHandler);
|
||||
else defaultHandler(warning);
|
||||
} } });
|
||||
|
||||
//#endregion
|
||||
//#region src/index.ts
|
||||
const _dirname = typeof __dirname !== "undefined" ? __dirname : dirname(fileURLToPath(import.meta.url));
|
||||
const resolve = createRequire(typeof __filename !== "undefined" ? __filename : import.meta.url).resolve;
|
||||
const react = (_options) => {
|
||||
let hmrDisabled = false;
|
||||
const options = {
|
||||
jsxImportSource: _options?.jsxImportSource ?? "react",
|
||||
tsDecorators: _options?.tsDecorators,
|
||||
plugins: _options?.plugins ? _options?.plugins.map((el) => [resolve(el[0]), el[1]]) : void 0,
|
||||
devTarget: _options?.devTarget ?? "es2020",
|
||||
parserConfig: _options?.parserConfig,
|
||||
reactRefreshHost: _options?.reactRefreshHost,
|
||||
useAtYourOwnRisk_mutateSwcOptions: _options?.useAtYourOwnRisk_mutateSwcOptions,
|
||||
disableOxcRecommendation: _options?.disableOxcRecommendation
|
||||
};
|
||||
return [
|
||||
{
|
||||
name: "vite:react-swc:resolve-runtime",
|
||||
apply: "serve",
|
||||
enforce: "pre",
|
||||
resolveId: {
|
||||
filter: { id: exactRegex(runtimePublicPath) },
|
||||
handler: (id) => id === runtimePublicPath ? id : void 0
|
||||
},
|
||||
load: {
|
||||
filter: { id: exactRegex(runtimePublicPath) },
|
||||
handler: (id) => id === runtimePublicPath ? readFileSync(join(_dirname, "refresh-runtime.js"), "utf-8").replace(/__README_URL__/g, "https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react-swc") : void 0
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "vite:react-swc",
|
||||
apply: "serve",
|
||||
config: () => ({
|
||||
esbuild: false,
|
||||
oxc: false,
|
||||
optimizeDeps: {
|
||||
include: [`${options.jsxImportSource}/jsx-dev-runtime`],
|
||||
..."rolldownVersion" in vite ? { rollupOptions: { jsx: { mode: "automatic" } } } : { esbuildOptions: { jsx: "automatic" } }
|
||||
}
|
||||
}),
|
||||
configResolved(config) {
|
||||
if (config.server.hmr === false) hmrDisabled = true;
|
||||
const mdxIndex = config.plugins.findIndex((p) => p.name === "@mdx-js/rollup");
|
||||
if (mdxIndex !== -1 && mdxIndex > config.plugins.findIndex((p) => p.name === "vite:react-swc")) throw new Error("[vite:react-swc] The MDX plugin should be placed before this plugin");
|
||||
if ("rolldownVersion" in vite && !options.plugins && !options.useAtYourOwnRisk_mutateSwcOptions && !options.disableOxcRecommendation) config.logger.warn("[vite:react-swc] We recommend switching to `@vitejs/plugin-react-oxc` for improved performance as no swc plugins are used. More information at https://vite.dev/rolldown");
|
||||
},
|
||||
transformIndexHtml: (_, config) => {
|
||||
if (!hmrDisabled) return [{
|
||||
tag: "script",
|
||||
attrs: { type: "module" },
|
||||
children: getPreambleCode(config.server.config.base)
|
||||
}];
|
||||
},
|
||||
async transform(code, _id, transformOptions) {
|
||||
const id = _id.split("?")[0];
|
||||
const refresh = !transformOptions?.ssr && !hmrDisabled;
|
||||
const result = await transformWithOptions(id, code, options.devTarget, options, {
|
||||
refresh,
|
||||
development: true,
|
||||
runtime: "automatic",
|
||||
importSource: options.jsxImportSource
|
||||
});
|
||||
if (!result) return;
|
||||
if (!refresh) return result;
|
||||
return addRefreshWrapper(result.code, result.map, "@vitejs/plugin-react-swc", id, options.reactRefreshHost);
|
||||
}
|
||||
},
|
||||
options.plugins ? {
|
||||
name: "vite:react-swc",
|
||||
apply: "build",
|
||||
enforce: "pre",
|
||||
config: (userConfig) => ({ build: silenceUseClientWarning(userConfig) }),
|
||||
transform: (code, _id) => transformWithOptions(_id.split("?")[0], code, "esnext", options, {
|
||||
runtime: "automatic",
|
||||
importSource: options.jsxImportSource
|
||||
})
|
||||
} : {
|
||||
name: "vite:react-swc",
|
||||
apply: "build",
|
||||
config: (userConfig) => ({
|
||||
build: silenceUseClientWarning(userConfig),
|
||||
esbuild: {
|
||||
jsx: "automatic",
|
||||
jsxImportSource: options.jsxImportSource,
|
||||
tsconfigRaw: { compilerOptions: { useDefineForClassFields: true } }
|
||||
}
|
||||
})
|
||||
}
|
||||
];
|
||||
};
|
||||
const transformWithOptions = async (id, code, target, options, reactConfig) => {
|
||||
const decorators = options?.tsDecorators ?? false;
|
||||
const parser = options.parserConfig ? options.parserConfig(id) : id.endsWith(".tsx") ? {
|
||||
syntax: "typescript",
|
||||
tsx: true,
|
||||
decorators
|
||||
} : id.endsWith(".ts") || id.endsWith(".mts") ? {
|
||||
syntax: "typescript",
|
||||
tsx: false,
|
||||
decorators
|
||||
} : id.endsWith(".jsx") ? {
|
||||
syntax: "ecmascript",
|
||||
jsx: true
|
||||
} : id.endsWith(".mdx") ? {
|
||||
syntax: "ecmascript",
|
||||
jsx: true
|
||||
} : void 0;
|
||||
if (!parser) return;
|
||||
let result;
|
||||
try {
|
||||
const swcOptions = {
|
||||
filename: id,
|
||||
swcrc: false,
|
||||
configFile: false,
|
||||
sourceMaps: true,
|
||||
jsc: {
|
||||
target,
|
||||
parser,
|
||||
experimental: { plugins: options.plugins },
|
||||
transform: {
|
||||
useDefineForClassFields: true,
|
||||
react: reactConfig
|
||||
}
|
||||
}
|
||||
};
|
||||
if (options.useAtYourOwnRisk_mutateSwcOptions) options.useAtYourOwnRisk_mutateSwcOptions(swcOptions);
|
||||
result = await transform(code, swcOptions);
|
||||
} catch (e) {
|
||||
const message = e.message;
|
||||
const fileStartIndex = message.indexOf("╭─[");
|
||||
if (fileStartIndex !== -1) {
|
||||
const match = message.slice(fileStartIndex).match(/:(\d+):(\d+)\]/);
|
||||
if (match) {
|
||||
e.line = match[1];
|
||||
e.column = match[2];
|
||||
}
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return result;
|
||||
};
|
||||
var src_default = react;
|
||||
|
||||
//#endregion
|
||||
export { src_default as default };
|
||||
41
frontend/node_modules/@vitejs/plugin-react-swc/package.json
generated
vendored
Normal file
41
frontend/node_modules/@vitejs/plugin-react-swc/package.json
generated
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
{
|
||||
"name": "@vitejs/plugin-react-swc",
|
||||
"version": "3.11.0",
|
||||
"license": "MIT",
|
||||
"author": "Arnaud Barré (https://github.com/ArnaudBarre)",
|
||||
"description": "Speed up your Vite dev server with SWC",
|
||||
"keywords": [
|
||||
"vite",
|
||||
"vite-plugin",
|
||||
"react",
|
||||
"swc",
|
||||
"react-refresh",
|
||||
"fast refresh"
|
||||
],
|
||||
"type": "module",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/vitejs/vite-plugin-react.git",
|
||||
"directory": "packages/plugin-react-swc"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/vitejs/vite-plugin-react/issues"
|
||||
},
|
||||
"homepage": "https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react-swc#readme",
|
||||
"dependencies": {
|
||||
"@rolldown/pluginutils": "1.0.0-beta.27",
|
||||
"@swc/core": "^1.12.11"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"vite": "^4 || ^5 || ^6 || ^7"
|
||||
},
|
||||
"main": "index.cjs",
|
||||
"types": "index.d.ts",
|
||||
"module": "index.js",
|
||||
"exports": {
|
||||
".": {
|
||||
"require": "./index.cjs",
|
||||
"import": "./index.js"
|
||||
}
|
||||
}
|
||||
}
|
||||
140
frontend/node_modules/@vitejs/plugin-react/README.md
generated
vendored
140
frontend/node_modules/@vitejs/plugin-react/README.md
generated
vendored
@ -1,140 +0,0 @@
|
||||
# @vitejs/plugin-react [](https://npmjs.com/package/@vitejs/plugin-react)
|
||||
|
||||
The default Vite plugin for React projects.
|
||||
|
||||
- enable [Fast Refresh](https://www.npmjs.com/package/react-refresh) in development (requires react >= 16.9)
|
||||
- use the [automatic JSX runtime](https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html)
|
||||
- use custom Babel plugins/presets
|
||||
- small installation size
|
||||
|
||||
```js
|
||||
// vite.config.js
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
})
|
||||
```
|
||||
|
||||
## Options
|
||||
|
||||
### include/exclude
|
||||
|
||||
Includes `.js`, `.jsx`, `.ts` & `.tsx` and excludes `/node_modules/` by default. This option can be used to add fast refresh to `.mdx` files:
|
||||
|
||||
```js
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
import mdx from '@mdx-js/rollup'
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
{ enforce: 'pre', ...mdx() },
|
||||
react({ include: /\.(mdx|js|jsx|ts|tsx)$/ }),
|
||||
],
|
||||
})
|
||||
```
|
||||
|
||||
### jsxImportSource
|
||||
|
||||
Control where the JSX factory is imported from. By default, this is inferred from `jsxImportSource` from corresponding a tsconfig file for a transformed file.
|
||||
|
||||
```js
|
||||
react({ jsxImportSource: '@emotion/react' })
|
||||
```
|
||||
|
||||
### jsxRuntime
|
||||
|
||||
By default, the plugin uses the [automatic JSX runtime](https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html). However, if you encounter any issues, you may opt out using the `jsxRuntime` option.
|
||||
|
||||
```js
|
||||
react({ jsxRuntime: 'classic' })
|
||||
```
|
||||
|
||||
### babel
|
||||
|
||||
The `babel` option lets you add plugins, presets, and [other configuration](https://babeljs.io/docs/en/options) to the Babel transformation performed on each included file.
|
||||
|
||||
```js
|
||||
react({
|
||||
babel: {
|
||||
presets: [...],
|
||||
// Your plugins run before any built-in transform (eg: Fast Refresh)
|
||||
plugins: [...],
|
||||
// Use .babelrc files
|
||||
babelrc: true,
|
||||
// Use babel.config.js files
|
||||
configFile: true,
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
Note: When not using plugins, only esbuild is used for production builds, resulting in faster builds.
|
||||
|
||||
#### Proposed syntax
|
||||
|
||||
If you are using ES syntax that are still in proposal status (e.g. class properties), you can selectively enable them with the `babel.parserOpts.plugins` option:
|
||||
|
||||
```js
|
||||
react({
|
||||
babel: {
|
||||
parserOpts: {
|
||||
plugins: ['decorators-legacy'],
|
||||
},
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
This option does not enable _code transformation_. That is handled by esbuild.
|
||||
|
||||
**Note:** TypeScript syntax is handled automatically.
|
||||
|
||||
Here's the [complete list of Babel parser plugins](https://babeljs.io/docs/en/babel-parser#ecmascript-proposalshttpsgithubcombabelproposals).
|
||||
|
||||
### reactRefreshHost
|
||||
|
||||
The `reactRefreshHost` option is only necessary in a module federation context. It enables HMR to work between a remote & host application. In your remote Vite config, you would add your host origin:
|
||||
|
||||
```js
|
||||
react({ reactRefreshHost: 'http://localhost:3000' })
|
||||
```
|
||||
|
||||
Under the hood, this simply updates the React Fash Refresh runtime URL from `/@react-refresh` to `http://localhost:3000/@react-refresh` to ensure there is only one Refresh runtime across the whole application. Note that if you define `base` option in the host application, you need to include it in the option, like: `http://localhost:3000/{base}`.
|
||||
|
||||
## Middleware mode
|
||||
|
||||
In [middleware mode](https://vite.dev/config/server-options.html#server-middlewaremode), you should make sure your entry `index.html` file is transformed by Vite. Here's an example for an Express server:
|
||||
|
||||
```js
|
||||
app.get('/', async (req, res, next) => {
|
||||
try {
|
||||
let html = fs.readFileSync(path.resolve(root, 'index.html'), 'utf-8')
|
||||
|
||||
// Transform HTML using Vite plugins.
|
||||
html = await viteServer.transformIndexHtml(req.url, html)
|
||||
|
||||
res.send(html)
|
||||
} catch (e) {
|
||||
return next(e)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
Otherwise, you'll probably get this error:
|
||||
|
||||
```
|
||||
Uncaught Error: @vitejs/plugin-react can't detect preamble. Something is wrong.
|
||||
```
|
||||
|
||||
### disableOxcRecommendation
|
||||
|
||||
If set, disables the recommendation to use `@vitejs/plugin-react-oxc` (which is shown when `rolldown-vite` is detected and `babel` is not configured).
|
||||
|
||||
## Consistent components exports
|
||||
|
||||
For React refresh to work correctly, your file should only export React components. You can find a good explanation in the [Gatsby docs](https://www.gatsbyjs.com/docs/reference/local-development/fast-refresh/#how-it-works).
|
||||
|
||||
If an incompatible change in exports is found, the module will be invalidated and HMR will propagate. To make it easier to export simple constants alongside your component, the module is only invalidated when their value changes.
|
||||
|
||||
You can catch mistakes and get more detailed warning with this [eslint rule](https://github.com/ArnaudBarre/eslint-plugin-react-refresh).
|
||||
64
frontend/node_modules/@vitejs/plugin-react/dist/index.d.ts
generated
vendored
64
frontend/node_modules/@vitejs/plugin-react/dist/index.d.ts
generated
vendored
@ -1,64 +0,0 @@
|
||||
import { Plugin, ResolvedConfig } from "vite";
|
||||
import { ParserOptions, TransformOptions } from "@babel/core";
|
||||
|
||||
//#region src/index.d.ts
|
||||
interface Options {
|
||||
include?: string | RegExp | Array<string | RegExp>;
|
||||
exclude?: string | RegExp | Array<string | RegExp>;
|
||||
/**
|
||||
* Control where the JSX factory is imported from.
|
||||
* https://esbuild.github.io/api/#jsx-import-source
|
||||
* @default 'react'
|
||||
*/
|
||||
jsxImportSource?: string;
|
||||
/**
|
||||
* Note: Skipping React import with classic runtime is not supported from v4
|
||||
* @default "automatic"
|
||||
*/
|
||||
jsxRuntime?: 'classic' | 'automatic';
|
||||
/**
|
||||
* Babel configuration applied in both dev and prod.
|
||||
*/
|
||||
babel?: BabelOptions | ((id: string, options: {
|
||||
ssr?: boolean;
|
||||
}) => BabelOptions);
|
||||
/**
|
||||
* React Fast Refresh runtime URL prefix.
|
||||
* Useful in a module federation context to enable HMR by specifying
|
||||
* the host application URL in the Vite config of a remote application.
|
||||
* @example
|
||||
* reactRefreshHost: 'http://localhost:3000'
|
||||
*/
|
||||
reactRefreshHost?: string;
|
||||
}
|
||||
type BabelOptions = Omit<TransformOptions, 'ast' | 'filename' | 'root' | 'sourceFileName' | 'sourceMaps' | 'inputSourceMap'>;
|
||||
/**
|
||||
* The object type used by the `options` passed to plugins with
|
||||
* an `api.reactBabel` method.
|
||||
*/
|
||||
interface ReactBabelOptions extends BabelOptions {
|
||||
plugins: Extract<BabelOptions['plugins'], any[]>;
|
||||
presets: Extract<BabelOptions['presets'], any[]>;
|
||||
overrides: Extract<BabelOptions['overrides'], any[]>;
|
||||
parserOpts: ParserOptions & {
|
||||
plugins: Extract<ParserOptions['plugins'], any[]>;
|
||||
};
|
||||
}
|
||||
type ReactBabelHook = (babelConfig: ReactBabelOptions, context: ReactBabelHookContext, config: ResolvedConfig) => void;
|
||||
type ReactBabelHookContext = {
|
||||
ssr: boolean;
|
||||
id: string;
|
||||
};
|
||||
type ViteReactPluginApi = {
|
||||
/**
|
||||
* Manipulate the Babel options of `@vitejs/plugin-react`
|
||||
*/
|
||||
reactBabel?: ReactBabelHook;
|
||||
};
|
||||
declare function viteReact(opts?: Options): Plugin[];
|
||||
declare namespace viteReact {
|
||||
var preambleCode: string;
|
||||
}
|
||||
declare function viteReactForCjs(this: unknown, options: Options): Plugin[];
|
||||
//#endregion
|
||||
export { BabelOptions, Options, ReactBabelOptions, ViteReactPluginApi, viteReact as default, viteReactForCjs as "module.exports" };
|
||||
368
frontend/node_modules/@vitejs/plugin-react/dist/index.js
generated
vendored
368
frontend/node_modules/@vitejs/plugin-react/dist/index.js
generated
vendored
@ -1,368 +0,0 @@
|
||||
import { dirname, join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { readFileSync } from "node:fs";
|
||||
import * as vite from "vite";
|
||||
import { createFilter } from "vite";
|
||||
import { exactRegex, makeIdFiltersToMatchWithQuery } from "@rolldown/pluginutils";
|
||||
|
||||
//#region ../common/refresh-utils.ts
|
||||
const runtimePublicPath = "/@react-refresh";
|
||||
const reactCompRE = /extends\s+(?:React\.)?(?:Pure)?Component/;
|
||||
const refreshContentRE = /\$RefreshReg\$\(/;
|
||||
const preambleCode = `import { injectIntoGlobalHook } from "__BASE__${runtimePublicPath.slice(1)}";
|
||||
injectIntoGlobalHook(window);
|
||||
window.$RefreshReg$ = () => {};
|
||||
window.$RefreshSig$ = () => (type) => type;`;
|
||||
const getPreambleCode = (base) => preambleCode.replace("__BASE__", base);
|
||||
const avoidSourceMapOption = Symbol();
|
||||
function addRefreshWrapper(code, map, pluginName, id, reactRefreshHost = "") {
|
||||
const hasRefresh = refreshContentRE.test(code);
|
||||
const onlyReactComp = !hasRefresh && reactCompRE.test(code);
|
||||
const normalizedMap = map === avoidSourceMapOption ? null : map;
|
||||
if (!hasRefresh && !onlyReactComp) return {
|
||||
code,
|
||||
map: normalizedMap
|
||||
};
|
||||
const avoidSourceMap = map === avoidSourceMapOption;
|
||||
const newMap = typeof normalizedMap === "string" ? JSON.parse(normalizedMap) : normalizedMap;
|
||||
let newCode = code;
|
||||
if (hasRefresh) {
|
||||
const refreshHead = removeLineBreaksIfNeeded(`let prevRefreshReg;
|
||||
let prevRefreshSig;
|
||||
|
||||
if (import.meta.hot && !inWebWorker) {
|
||||
if (!window.$RefreshReg$) {
|
||||
throw new Error(
|
||||
"${pluginName} can't detect preamble. Something is wrong."
|
||||
);
|
||||
}
|
||||
|
||||
prevRefreshReg = window.$RefreshReg$;
|
||||
prevRefreshSig = window.$RefreshSig$;
|
||||
window.$RefreshReg$ = RefreshRuntime.getRefreshReg(${JSON.stringify(id)});
|
||||
window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
|
||||
}
|
||||
|
||||
`, avoidSourceMap);
|
||||
newCode = `${refreshHead}${newCode}
|
||||
|
||||
if (import.meta.hot && !inWebWorker) {
|
||||
window.$RefreshReg$ = prevRefreshReg;
|
||||
window.$RefreshSig$ = prevRefreshSig;
|
||||
}
|
||||
`;
|
||||
if (newMap) newMap.mappings = ";".repeat(16) + newMap.mappings;
|
||||
}
|
||||
const sharedHead = removeLineBreaksIfNeeded(`import * as RefreshRuntime from "${reactRefreshHost}${runtimePublicPath}";
|
||||
const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
|
||||
|
||||
`, avoidSourceMap);
|
||||
newCode = `${sharedHead}${newCode}
|
||||
|
||||
if (import.meta.hot && !inWebWorker) {
|
||||
RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
|
||||
RefreshRuntime.registerExportsForReactRefresh(${JSON.stringify(id)}, currentExports);
|
||||
import.meta.hot.accept((nextExports) => {
|
||||
if (!nextExports) return;
|
||||
const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate(${JSON.stringify(id)}, currentExports, nextExports);
|
||||
if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
|
||||
});
|
||||
});
|
||||
}
|
||||
`;
|
||||
if (newMap) newMap.mappings = ";;;" + newMap.mappings;
|
||||
return {
|
||||
code: newCode,
|
||||
map: newMap
|
||||
};
|
||||
}
|
||||
function removeLineBreaksIfNeeded(code, enabled) {
|
||||
return enabled ? code.replace(/\n/g, "") : code;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region ../common/warning.ts
|
||||
const silenceUseClientWarning = (userConfig) => ({ rollupOptions: { onwarn(warning, defaultHandler) {
|
||||
if (warning.code === "MODULE_LEVEL_DIRECTIVE" && (warning.message.includes("use client") || warning.message.includes("use server"))) return;
|
||||
if (warning.code === "SOURCEMAP_ERROR" && warning.message.includes("resolve original location") && warning.pos === 0) return;
|
||||
if (userConfig.build?.rollupOptions?.onwarn) userConfig.build.rollupOptions.onwarn(warning, defaultHandler);
|
||||
else defaultHandler(warning);
|
||||
} } });
|
||||
|
||||
//#endregion
|
||||
//#region src/index.ts
|
||||
const _dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const refreshRuntimePath = join(_dirname, "refresh-runtime.js");
|
||||
let babel;
|
||||
async function loadBabel() {
|
||||
if (!babel) babel = await import("@babel/core");
|
||||
return babel;
|
||||
}
|
||||
const defaultIncludeRE = /\.[tj]sx?$/;
|
||||
const defaultExcludeRE = /\/node_modules\//;
|
||||
const tsRE = /\.tsx?$/;
|
||||
const compilerAnnotationRE = /['"]use memo['"]/;
|
||||
function viteReact(opts = {}) {
|
||||
const include = opts.include ?? defaultIncludeRE;
|
||||
const exclude = opts.exclude ?? defaultExcludeRE;
|
||||
const filter = createFilter(include, exclude);
|
||||
const jsxImportSource = opts.jsxImportSource ?? "react";
|
||||
const jsxImportRuntime = `${jsxImportSource}/jsx-runtime`;
|
||||
const jsxImportDevRuntime = `${jsxImportSource}/jsx-dev-runtime`;
|
||||
const isRolldownVite = "rolldownVersion" in vite;
|
||||
let runningInVite = false;
|
||||
let isProduction = true;
|
||||
let projectRoot = process.cwd();
|
||||
let skipFastRefresh = true;
|
||||
let runPluginOverrides;
|
||||
let staticBabelOptions;
|
||||
const importReactRE = /\bimport\s+(?:\*\s+as\s+)?React\b/;
|
||||
const viteBabel = {
|
||||
name: "vite:react-babel",
|
||||
enforce: "pre",
|
||||
config(_userConfig, { command }) {
|
||||
if ("rolldownVersion" in vite) if (opts.jsxRuntime === "classic") return { oxc: {
|
||||
jsx: {
|
||||
runtime: "classic",
|
||||
refresh: command === "serve",
|
||||
development: false
|
||||
},
|
||||
jsxRefreshInclude: include,
|
||||
jsxRefreshExclude: exclude
|
||||
} };
|
||||
else return {
|
||||
oxc: {
|
||||
jsx: {
|
||||
runtime: "automatic",
|
||||
importSource: opts.jsxImportSource,
|
||||
refresh: command === "serve"
|
||||
},
|
||||
jsxRefreshInclude: include,
|
||||
jsxRefreshExclude: exclude
|
||||
},
|
||||
optimizeDeps: { rollupOptions: { transform: { jsx: { runtime: "automatic" } } } }
|
||||
};
|
||||
if (opts.jsxRuntime === "classic") return { esbuild: { jsx: "transform" } };
|
||||
else return {
|
||||
esbuild: {
|
||||
jsx: "automatic",
|
||||
jsxImportSource: opts.jsxImportSource
|
||||
},
|
||||
optimizeDeps: { esbuildOptions: { jsx: "automatic" } }
|
||||
};
|
||||
},
|
||||
configResolved(config) {
|
||||
runningInVite = true;
|
||||
projectRoot = config.root;
|
||||
isProduction = config.isProduction;
|
||||
skipFastRefresh = isProduction || config.command === "build" || config.server.hmr === false;
|
||||
const hooks = config.plugins.map((plugin) => plugin.api?.reactBabel).filter(defined);
|
||||
if (hooks.length > 0) runPluginOverrides = (babelOptions, context) => {
|
||||
hooks.forEach((hook) => hook(babelOptions, context, config));
|
||||
};
|
||||
else if (typeof opts.babel !== "function") {
|
||||
staticBabelOptions = createBabelOptions(opts.babel);
|
||||
if ((isRolldownVite || skipFastRefresh) && canSkipBabel(staticBabelOptions.plugins, staticBabelOptions) && (opts.jsxRuntime === "classic" ? isProduction : true)) delete viteBabel.transform;
|
||||
}
|
||||
},
|
||||
options(options) {
|
||||
if (!runningInVite) {
|
||||
options.jsx = {
|
||||
mode: opts.jsxRuntime,
|
||||
importSource: opts.jsxImportSource
|
||||
};
|
||||
return options;
|
||||
}
|
||||
},
|
||||
transform: {
|
||||
filter: { id: {
|
||||
include: makeIdFiltersToMatchWithQuery(include),
|
||||
exclude: makeIdFiltersToMatchWithQuery(exclude)
|
||||
} },
|
||||
async handler(code, id, options) {
|
||||
const [filepath] = id.split("?");
|
||||
if (!filter(filepath)) return;
|
||||
const ssr = options?.ssr === true;
|
||||
const babelOptions = (() => {
|
||||
if (staticBabelOptions) return staticBabelOptions;
|
||||
const newBabelOptions = createBabelOptions(typeof opts.babel === "function" ? opts.babel(id, { ssr }) : opts.babel);
|
||||
runPluginOverrides?.(newBabelOptions, {
|
||||
id,
|
||||
ssr
|
||||
});
|
||||
return newBabelOptions;
|
||||
})();
|
||||
const plugins = [...babelOptions.plugins];
|
||||
let reactCompilerPlugin$1 = getReactCompilerPlugin(plugins);
|
||||
if (reactCompilerPlugin$1 && ssr) {
|
||||
plugins.splice(plugins.indexOf(reactCompilerPlugin$1), 1);
|
||||
reactCompilerPlugin$1 = void 0;
|
||||
}
|
||||
if (Array.isArray(reactCompilerPlugin$1) && reactCompilerPlugin$1[1]?.compilationMode === "annotation" && !compilerAnnotationRE.test(code)) {
|
||||
plugins.splice(plugins.indexOf(reactCompilerPlugin$1), 1);
|
||||
reactCompilerPlugin$1 = void 0;
|
||||
}
|
||||
const isJSX = filepath.endsWith("x");
|
||||
const useFastRefresh = !(isRolldownVite || skipFastRefresh) && !ssr && (isJSX || (opts.jsxRuntime === "classic" ? importReactRE.test(code) : code.includes(jsxImportDevRuntime) || code.includes(jsxImportRuntime)));
|
||||
if (useFastRefresh) plugins.push([await loadPlugin("react-refresh/babel"), { skipEnvCheck: true }]);
|
||||
if (opts.jsxRuntime === "classic" && isJSX) {
|
||||
if (!isProduction) plugins.push(await loadPlugin("@babel/plugin-transform-react-jsx-self"), await loadPlugin("@babel/plugin-transform-react-jsx-source"));
|
||||
}
|
||||
if (canSkipBabel(plugins, babelOptions)) return;
|
||||
const parserPlugins = [...babelOptions.parserOpts.plugins];
|
||||
if (!filepath.endsWith(".ts")) parserPlugins.push("jsx");
|
||||
if (tsRE.test(filepath)) parserPlugins.push("typescript");
|
||||
const babel$1 = await loadBabel();
|
||||
const result = await babel$1.transformAsync(code, {
|
||||
...babelOptions,
|
||||
root: projectRoot,
|
||||
filename: id,
|
||||
sourceFileName: filepath,
|
||||
retainLines: reactCompilerPlugin$1 ? false : !isProduction && isJSX && opts.jsxRuntime !== "classic",
|
||||
parserOpts: {
|
||||
...babelOptions.parserOpts,
|
||||
sourceType: "module",
|
||||
allowAwaitOutsideFunction: true,
|
||||
plugins: parserPlugins
|
||||
},
|
||||
generatorOpts: {
|
||||
...babelOptions.generatorOpts,
|
||||
importAttributesKeyword: "with",
|
||||
decoratorsBeforeExport: true
|
||||
},
|
||||
plugins,
|
||||
sourceMaps: true
|
||||
});
|
||||
if (result) {
|
||||
if (!useFastRefresh) return {
|
||||
code: result.code,
|
||||
map: result.map
|
||||
};
|
||||
return addRefreshWrapper(result.code, result.map, "@vitejs/plugin-react", id, opts.reactRefreshHost);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
const viteRefreshWrapper = {
|
||||
name: "vite:react:refresh-wrapper",
|
||||
apply: "serve",
|
||||
transform: {
|
||||
filter: { id: {
|
||||
include: makeIdFiltersToMatchWithQuery(include),
|
||||
exclude: makeIdFiltersToMatchWithQuery(exclude)
|
||||
} },
|
||||
handler(code, id, options) {
|
||||
const ssr = options?.ssr === true;
|
||||
const [filepath] = id.split("?");
|
||||
const isJSX = filepath.endsWith("x");
|
||||
const useFastRefresh = !skipFastRefresh && !ssr && (isJSX || code.includes(jsxImportDevRuntime) || code.includes(jsxImportRuntime));
|
||||
if (!useFastRefresh) return;
|
||||
const { code: newCode } = addRefreshWrapper(code, avoidSourceMapOption, "@vitejs/plugin-react", id, opts.reactRefreshHost);
|
||||
return {
|
||||
code: newCode,
|
||||
map: null
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
const viteConfigPost = {
|
||||
name: "vite:react:config-post",
|
||||
enforce: "post",
|
||||
config(userConfig) {
|
||||
if (userConfig.server?.hmr === false) return { oxc: { jsx: { refresh: false } } };
|
||||
}
|
||||
};
|
||||
const dependencies = [
|
||||
"react",
|
||||
"react-dom",
|
||||
jsxImportDevRuntime,
|
||||
jsxImportRuntime
|
||||
];
|
||||
const staticBabelPlugins = typeof opts.babel === "object" ? opts.babel?.plugins ?? [] : [];
|
||||
const reactCompilerPlugin = getReactCompilerPlugin(staticBabelPlugins);
|
||||
if (reactCompilerPlugin != null) {
|
||||
const reactCompilerRuntimeModule = getReactCompilerRuntimeModule(reactCompilerPlugin);
|
||||
dependencies.push(reactCompilerRuntimeModule);
|
||||
}
|
||||
const viteReactRefresh = {
|
||||
name: "vite:react-refresh",
|
||||
enforce: "pre",
|
||||
config: (userConfig) => ({
|
||||
build: silenceUseClientWarning(userConfig),
|
||||
optimizeDeps: { include: dependencies }
|
||||
}),
|
||||
resolveId: {
|
||||
filter: { id: exactRegex(runtimePublicPath) },
|
||||
handler(id) {
|
||||
if (id === runtimePublicPath) return id;
|
||||
}
|
||||
},
|
||||
load: {
|
||||
filter: { id: exactRegex(runtimePublicPath) },
|
||||
handler(id) {
|
||||
if (id === runtimePublicPath) return readFileSync(refreshRuntimePath, "utf-8").replace(/__README_URL__/g, "https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react");
|
||||
}
|
||||
},
|
||||
transformIndexHtml(_, config) {
|
||||
if (!skipFastRefresh) return [{
|
||||
tag: "script",
|
||||
attrs: { type: "module" },
|
||||
children: getPreambleCode(config.server.config.base)
|
||||
}];
|
||||
}
|
||||
};
|
||||
return [
|
||||
viteBabel,
|
||||
...isRolldownVite ? [viteRefreshWrapper, viteConfigPost] : [],
|
||||
viteReactRefresh
|
||||
];
|
||||
}
|
||||
viteReact.preambleCode = preambleCode;
|
||||
function viteReactForCjs(options) {
|
||||
return viteReact.call(this, options);
|
||||
}
|
||||
Object.assign(viteReactForCjs, { default: viteReactForCjs });
|
||||
function canSkipBabel(plugins, babelOptions) {
|
||||
return !(plugins.length || babelOptions.presets.length || babelOptions.configFile || babelOptions.babelrc);
|
||||
}
|
||||
const loadedPlugin = /* @__PURE__ */ new Map();
|
||||
function loadPlugin(path) {
|
||||
const cached = loadedPlugin.get(path);
|
||||
if (cached) return cached;
|
||||
const promise = import(path).then((module) => {
|
||||
const value = module.default || module;
|
||||
loadedPlugin.set(path, value);
|
||||
return value;
|
||||
});
|
||||
loadedPlugin.set(path, promise);
|
||||
return promise;
|
||||
}
|
||||
function createBabelOptions(rawOptions) {
|
||||
const babelOptions = {
|
||||
babelrc: false,
|
||||
configFile: false,
|
||||
...rawOptions
|
||||
};
|
||||
babelOptions.plugins ||= [];
|
||||
babelOptions.presets ||= [];
|
||||
babelOptions.overrides ||= [];
|
||||
babelOptions.parserOpts ||= {};
|
||||
babelOptions.parserOpts.plugins ||= [];
|
||||
return babelOptions;
|
||||
}
|
||||
function defined(value) {
|
||||
return value !== void 0;
|
||||
}
|
||||
function getReactCompilerPlugin(plugins) {
|
||||
return plugins.find((p) => p === "babel-plugin-react-compiler" || Array.isArray(p) && p[0] === "babel-plugin-react-compiler");
|
||||
}
|
||||
function getReactCompilerRuntimeModule(plugin) {
|
||||
let moduleName = "react/compiler-runtime";
|
||||
if (Array.isArray(plugin)) {
|
||||
if (plugin[1]?.target === "17" || plugin[1]?.target === "18") moduleName = "react-compiler-runtime";
|
||||
}
|
||||
return moduleName;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
export { viteReact as default, viteReactForCjs as "module.exports" };
|
||||
62
frontend/node_modules/@vitejs/plugin-react/package.json
generated
vendored
62
frontend/node_modules/@vitejs/plugin-react/package.json
generated
vendored
@ -1,62 +0,0 @@
|
||||
{
|
||||
"name": "@vitejs/plugin-react",
|
||||
"version": "5.0.2",
|
||||
"license": "MIT",
|
||||
"author": "Evan You",
|
||||
"description": "The default Vite plugin for React projects",
|
||||
"keywords": [
|
||||
"vite",
|
||||
"vite-plugin",
|
||||
"react",
|
||||
"babel",
|
||||
"react-refresh",
|
||||
"fast refresh"
|
||||
],
|
||||
"contributors": [
|
||||
"Alec Larson",
|
||||
"Arnaud Barré"
|
||||
],
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"type": "module",
|
||||
"exports": "./dist/index.js",
|
||||
"scripts": {
|
||||
"dev": "tsdown --watch ./src --watch ../common",
|
||||
"build": "tsdown",
|
||||
"prepublishOnly": "npm run build",
|
||||
"test-unit": "vitest run"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^20.19.0 || >=22.12.0"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/vitejs/vite-plugin-react.git",
|
||||
"directory": "packages/plugin-react"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/vitejs/vite-plugin-react/issues"
|
||||
},
|
||||
"homepage": "https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react#readme",
|
||||
"dependencies": {
|
||||
"@babel/core": "^7.28.3",
|
||||
"@babel/plugin-transform-react-jsx-self": "^7.27.1",
|
||||
"@babel/plugin-transform-react-jsx-source": "^7.27.1",
|
||||
"@rolldown/pluginutils": "1.0.0-beta.34",
|
||||
"@types/babel__core": "^7.20.5",
|
||||
"react-refresh": "^0.17.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"vite": "^4.2.0 || ^5.0.0 || ^6.0.0 || ^7.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/react-common": "workspace:*",
|
||||
"babel-plugin-react-compiler": "19.1.0-rc.2",
|
||||
"react": "^19.1.1",
|
||||
"react-dom": "^19.1.1",
|
||||
"rolldown": "1.0.0-beta.34",
|
||||
"tsdown": "^0.14.2",
|
||||
"vitest": "^3.2.4"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user