This commit is contained in:
2025-06-16 13:37:14 +02:00
parent ac273655e6
commit a8b82208f7
5100 changed files with 737524 additions and 2 deletions

21
node_modules/@preact/preset-vite/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2021 The Preact Team
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

135
node_modules/@preact/preset-vite/README.md generated vendored Normal file
View File

@@ -0,0 +1,135 @@
# @preact/preset-vite
An all in one preset for writing Preact apps with the [vite](https://github.com/vitejs/vite) bundler.
Features:
- Sets up Hot Module Replacement via [prefresh](https://github.com/JoviDeCroock/prefresh/tree/main/packages/vite)
- Enables [Preact Devtools](https://preactjs.github.io/preact-devtools/) bridge during development
- Aliases React to `preact/compat`
## Installation
First intall the preset package from npm:
```bash
npm install --save-dev @preact/preset-vite
# or
yarn add -D @preact/preset-vite
```
Enhance your vite config with the Preact preset plugin in your `vite.config.ts` or `vite.config.js`:
```js
import { defineConfig } from "vite";
import preact from "@preact/preset-vite";
export default defineConfig({
plugins: [preact()]
});
```
## Options
Options can be passed to our preset plugin via the first argument:
```js
export default defineConfig({
plugins: [
preact({ devtoolsInProd: true })
]
});
```
### Available options
| Option | Type | Default | Description |
|---|---|---|---|
| `devtoolsInProd` | `boolean` | `false` | Inject devtools bridge in production bundle instead of only in development mode |
| `devToolsEnabled` | `boolean` | `true` | Inject devtools bridge |
| `prefreshEnabled` | `boolean` | `true` | Inject [Prefresh](https://github.com/preactjs/prefresh) for HMR |
| `reactAliasesEnabled` | `boolean` | `true` | Aliases `react`, `react-dom` to `preact/compat` |
| `babel` | `object` | | See [Babel configuration](#babel-configuration) |
| `prerender` | `object` | | See [Prerendering configuration](#prerendering-configuration) |
#### Babel configuration
The `babel` option lets you add plugins, presets, and [other configuration](https://babeljs.io/docs/en/options) to the Babel transformation performed on each JSX/TSX file.
```js
preact({
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,
}
})
```
#### Prerendering configuration
| Option | Type | Default | Description |
|---|---|---|---|
| `enabled` | `boolean` | `false` | Enables prerendering |
| `renderTarget` | `string` | `"body"` | Query selector for where to insert prerender result in your HTML template |
| `prerenderScript` | `string` | `undefined` | Absolute path to script containing exported `prerender()` function. If not provided, will try to find the prerender script in the scripts listed in your HTML entrypoint |
| `additionalPrerenderRoutes` | `string[]` | `undefined` | Prerendering will crawl your site automatically, but you'd like to prerender some pages that may not be found (such as a `/404` page), use this option to specify them |
| `previewMiddlewareEnabled` | `boolean` | `false` | Vite's preview server as of v5 will not use our prerendered HTML documents automatically. This option enables a middleware that will correct this, allowing you to test the result of prerendering locally |
| `previewMiddlewareFallback` | `string` | `/index.html` | Fallback path to be used when an HTML document cannot be found via the preview middleware, e.g., `/404` or `/not-found` will be used when the user requests `/some-path-that-does-not-exist` |
To prerender your app, you'll need to do these things:
1. Enable prerendering in the plugin options
2. Specify your render target, if you want the HTML to be inserted anywhere other than the `document.body`. This location likely should match `render()`, i.e., `render(<App />, document.querySelector('#app'))` -> `'#app'`
4. Create and export a `prerender()` function from a script. You could add this to your app entrypoint or create a completely separate file for it, either will work. See below for a usage example
5. Specify where your `prerender()` function is by either a) adding a `prerender` attribute to the script tag that contains it in your entry HTML (`<script prerender src="./my-prerender-script.js">`) or b) use the `prerenderScript` plugin option to specify the location with an absolute path
The plugin simply calls the prerender function you provide so it's up to you to determine how your app should be prerendered. You'll likely want to use [`preact-render-to-string`](https://github.com/preactjs/preact-render-to-string), or a wrapper around it such as [`preact-iso`'s `prerender`](https://github.com/preactjs/preact-iso), but whatever you choose, the minimum you'll need to return is an object containing an `html` property with your HTML string which will then be inserted according to your `renderTarget`.
Your `prerender()` function can be asynchronous, so feel free to make HTTP requests to retrieve data (`fetch(...)`), read files from disk (`fs.readFile(...)`), or similar things to set up your app.
[For a full example implementation, see our demo](./demo/src/index.tsx)
```js
import { prerender as ssr } from 'preact-iso';
function App() {
return <h1>Hello World!</h1>
}
export async function prerender(data) {
const { html, links: discoveredLinks } = ssr(<App />);
return {
html,
// Optionally add additional links that should be
// prerendered (if they haven't already been)
links: new Set([...discoveredLinks, '/foo', '/bar']),
// Optional data to serialize into a script tag for use on the client:
// <script type="application/json" id="preact-prerender-data">{"url":"/"}</script>
data: { url: data.url },
// Optionally configure and add elements to the `<head>` of
// the prerendered HTML document
head: {
// Sets the "lang" attribute: `<html lang="en">`
lang: 'en',
// Sets the title for the current page: `<title>My cool page</title>`
title: 'My cool page',
// Sets any additional elements you want injected into the `<head>`:
// <link rel="stylesheet" href="foo.css">
// <meta property="og:title" content="Social media title">
elements: new Set([
{ type: 'link', props: { rel: 'stylesheet', href: 'foo.css' } },
{ type: 'meta', props: { property: 'og:title', content: 'Social media title' } }
])
}
};
}
```
## License
MIT, see [the license file](./LICENSE).

View File

@@ -0,0 +1,8 @@
import { Plugin } from "vite";
import type { RollupFilter } from "./utils.js";
export interface PreactDevtoolsPluginOptions {
devtoolsInProd?: boolean;
devToolsEnabled?: boolean;
shouldTransform: RollupFilter;
}
export declare function preactDevtoolsPlugin({ devtoolsInProd, devToolsEnabled, shouldTransform, }: PreactDevtoolsPluginOptions): Plugin;

80
node_modules/@preact/preset-vite/dist/cjs/devtools.js generated vendored Normal file
View File

@@ -0,0 +1,80 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.preactDevtoolsPlugin = void 0;
const vite_1 = require("vite");
const path_1 = __importDefault(require("path"));
const debug_1 = __importDefault(require("debug"));
const kl = __importStar(require("kolorist"));
const utils_js_1 = require("./utils.js");
function preactDevtoolsPlugin({ devtoolsInProd, devToolsEnabled, shouldTransform, }) {
const log = (0, debug_1.default)("vite:preact-devtools");
let entry = "";
let config;
let found = false;
const plugin = {
name: "preact:devtools",
// Ensure that we resolve before everything else
enforce: "pre",
config() {
return {
optimizeDeps: {
include: ["preact/debug", "preact/devtools"],
},
};
},
configResolved(resolvedConfig) {
config = resolvedConfig;
devToolsEnabled =
devToolsEnabled !== null && devToolsEnabled !== void 0 ? devToolsEnabled : (!config.isProduction || devtoolsInProd);
},
resolveId(url, importer = "") {
const { id } = (0, utils_js_1.parseId)(url);
// Get the main entry file to inject into
if (!found && /\.html$/.test(importer) && shouldTransform(id)) {
found = true;
entry = (0, vite_1.normalizePath)(path_1.default.join(config.root, id));
// TODO: Vite types require explicit return
// undefined here. They're lacking the "void" type
// in their declarations
return undefined;
}
},
transform(code, url) {
const { id } = (0, utils_js_1.parseId)(url);
if (entry === id && (!config.isProduction || devToolsEnabled)) {
const source = config.isProduction ? "preact/devtools" : "preact/debug";
code = `import "${source}";\n${code}`;
log(`[inject] ${kl.cyan(source)} -> ${kl.dim(id)}`);
return code;
}
},
};
return plugin;
}
exports.preactDevtoolsPlugin = preactDevtoolsPlugin;

83
node_modules/@preact/preset-vite/dist/cjs/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,83 @@
import type { Plugin } from "vite";
import type { FilterPattern } from "@rollup/pluginutils";
import type { ParserOptions } from "@babel/parser";
import type { TransformOptions } from "@babel/core";
export type BabelOptions = Omit<TransformOptions, "ast" | "filename" | "root" | "sourceFileName" | "sourceMaps" | "inputSourceMap">;
export interface PreactPluginOptions {
/**
* Inject devtools bridge in production bundle instead of only in development mode.
* @default false
*/
devtoolsInProd?: boolean;
/**
* Whether to use Preact devtools
* @default true
*/
devToolsEnabled?: boolean;
/**
* Whether to use prefresh HMR
* @default true
*/
prefreshEnabled?: boolean;
/**
* Whether to alias react, react-dom to preact/compat
* @default true
*/
reactAliasesEnabled?: boolean;
/**
* Prerender plugin options
*/
prerender?: {
/**
* Whether to prerender your app on build
*/
enabled: boolean;
/**
* Absolute path to script containing an exported `prerender()` function
*/
prerenderScript?: string;
/**
* Query selector for specifying where to insert prerender result in your HTML template
*/
renderTarget?: string;
/**
* Additional routes that should be prerendered
*/
additionalPrerenderRoutes?: string[];
/**
* Vite's preview server won't use our prerendered HTML by default, this middleware correct this
*/
previewMiddlewareEnabled?: boolean;
/**
* Path to use as a fallback/404 route, i.e., `/404` or `/not-found`
*/
previewMiddlewareFallback?: string;
};
/**
* RegExp or glob to match files to be transformed
*/
include?: FilterPattern;
/**
* RegExp or glob to match files to NOT be transformed
*/
exclude?: FilterPattern;
/**
* Babel configuration applied in both dev and prod.
*/
babel?: BabelOptions;
/**
* Import Source for jsx. Defaults to "preact".
*/
jsxImportSource?: string;
}
export interface PreactBabelOptions extends BabelOptions {
plugins: Extract<BabelOptions["plugins"], any[]>;
presets: Extract<BabelOptions["presets"], any[]>;
overrides: Extract<BabelOptions["overrides"], any[]>;
parserOpts: ParserOptions & {
plugins: Extract<ParserOptions["plugins"], any[]>;
};
}
declare function preactPlugin({ devtoolsInProd, devToolsEnabled, prefreshEnabled, reactAliasesEnabled, prerender, include, exclude, babel, jsxImportSource, }?: PreactPluginOptions): Plugin[];
export default preactPlugin;
export { preactPlugin as preact };

175
node_modules/@preact/preset-vite/dist/cjs/index.js generated vendored Normal file
View File

@@ -0,0 +1,175 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.preact = void 0;
const vite_1 = __importDefault(require("@prefresh/vite"));
const devtools_js_1 = require("./devtools.js");
const utils_js_1 = require("./utils.js");
const vite_prerender_plugin_1 = require("vite-prerender-plugin");
const core_1 = require("@babel/core");
// @ts-ignore package doesn't ship with declaration files
const plugin_transform_react_jsx_1 = __importDefault(require("@babel/plugin-transform-react-jsx"));
// @ts-ignore package doesn't ship with declaration files
const plugin_transform_react_jsx_development_1 = __importDefault(require("@babel/plugin-transform-react-jsx-development"));
// @ts-ignore package doesn't ship with declaration files
const babel_plugin_transform_hook_names_1 = __importDefault(require("babel-plugin-transform-hook-names"));
// Taken from https://github.com/vitejs/vite/blob/main/packages/plugin-react/src/index.ts
function preactPlugin({ devtoolsInProd, devToolsEnabled, prefreshEnabled, reactAliasesEnabled, prerender, include, exclude, babel, jsxImportSource, } = {}) {
var _a;
const baseParserOptions = [
"importMeta",
"explicitResourceManagement",
"topLevelAwait",
];
let config;
let babelOptions = {
babelrc: false,
configFile: false,
...babel,
};
babelOptions.plugins || (babelOptions.plugins = []);
babelOptions.presets || (babelOptions.presets = []);
babelOptions.overrides || (babelOptions.overrides = []);
babelOptions.parserOpts || (babelOptions.parserOpts = {});
(_a = babelOptions.parserOpts).plugins || (_a.plugins = []);
let useBabel = typeof babel !== "undefined";
const shouldTransform = (0, utils_js_1.createFilter)(include || [/\.[cm]?[tj]sx?$/], exclude || [/node_modules/]);
devtoolsInProd = devtoolsInProd !== null && devtoolsInProd !== void 0 ? devtoolsInProd : false;
prefreshEnabled = prefreshEnabled !== null && prefreshEnabled !== void 0 ? prefreshEnabled : true;
reactAliasesEnabled = reactAliasesEnabled !== null && reactAliasesEnabled !== void 0 ? reactAliasesEnabled : true;
prerender = prerender !== null && prerender !== void 0 ? prerender : { enabled: false };
const prerenderPlugin = (0, vite_prerender_plugin_1.vitePrerenderPlugin)(prerender);
if (!prerender.previewMiddlewareEnabled) {
const idx = prerenderPlugin.findIndex(p => p.name == "serve-prerendered-html");
if (idx > -1) {
prerenderPlugin.splice(idx, 1);
}
}
const jsxPlugin = {
name: "vite:preact-jsx",
enforce: "pre",
config() {
return {
build: {
rollupOptions: {
onwarn(warning, warn) {
// Silence Rollup's module-level directive warnings re:"use client".
// They're likely to come from `node_modules` and won't be actionable.
if (warning.code === "MODULE_LEVEL_DIRECTIVE" &&
warning.message.includes("use client"))
return;
// ESBuild seemingly doesn't include mappings for directives, causing
// Rollup to emit warnings about missing source locations. This too is
// likely to come from `node_modules` and won't be actionable.
// evanw/esbuild#3548
if (warning.code === "SOURCEMAP_ERROR" &&
warning.message.includes("resolve original location") &&
warning.pos === 0)
return;
warn(warning);
},
},
},
esbuild: useBabel
? undefined
: {
jsx: "automatic",
jsxImportSource: jsxImportSource !== null && jsxImportSource !== void 0 ? jsxImportSource : "preact",
},
optimizeDeps: {
include: ["preact", "preact/jsx-runtime", "preact/jsx-dev-runtime"],
},
};
},
configResolved(resolvedConfig) {
config = resolvedConfig;
devToolsEnabled =
devToolsEnabled !== null && devToolsEnabled !== void 0 ? devToolsEnabled : (!config.isProduction || devtoolsInProd);
useBabel || (useBabel = !config.isProduction || !!devToolsEnabled);
},
async transform(code, url) {
// Ignore query parameters, as in Vue SFC virtual modules.
const { id } = (0, utils_js_1.parseId)(url);
if (!useBabel || !shouldTransform(id))
return;
const parserPlugins = [
...baseParserOptions,
"classProperties",
"classPrivateProperties",
"classPrivateMethods",
!id.endsWith(".ts") && "jsx",
/\.tsx?$/.test(id) && "typescript",
].filter(Boolean);
const result = await (0, core_1.transformAsync)(code, {
...babelOptions,
ast: true,
root: config.root,
filename: id,
parserOpts: {
...babelOptions.parserOpts,
sourceType: "module",
allowAwaitOutsideFunction: true,
plugins: parserPlugins,
},
generatorOpts: {
...babelOptions.generatorOpts,
decoratorsBeforeExport: true,
},
plugins: [
...babelOptions.plugins,
[
config.isProduction ? plugin_transform_react_jsx_1.default : plugin_transform_react_jsx_development_1.default,
{
runtime: "automatic",
importSource: jsxImportSource !== null && jsxImportSource !== void 0 ? jsxImportSource : "preact",
},
],
...(devToolsEnabled ? [babel_plugin_transform_hook_names_1.default] : []),
],
sourceMaps: true,
inputSourceMap: false,
});
// NOTE: Since no config file is being loaded, this path wouldn't occur.
if (!result)
return;
return {
code: result.code || code,
map: result.map,
};
},
};
return [
...(reactAliasesEnabled
? [
{
name: "preact:config",
config() {
return {
resolve: {
alias: {
"react-dom/test-utils": "preact/test-utils",
"react-dom": "preact/compat",
react: "preact/compat",
},
},
};
},
},
]
: []),
jsxPlugin,
(0, devtools_js_1.preactDevtoolsPlugin)({
devtoolsInProd,
devToolsEnabled,
shouldTransform,
}),
...(prefreshEnabled
? [(0, vite_1.default)({ include, exclude, parserPlugins: baseParserOptions })]
: []),
...(prerender.enabled ? prerenderPlugin : []),
];
}
exports.preact = preactPlugin;
exports.default = preactPlugin;

6
node_modules/@preact/preset-vite/dist/cjs/utils.d.ts generated vendored Normal file
View File

@@ -0,0 +1,6 @@
import type { CreateFilter } from "@rollup/pluginutils";
export { createFilter } from "@rollup/pluginutils";
export type RollupFilter = ReturnType<CreateFilter>;
export declare function parseId(url: string): {
id: string;
};

10
node_modules/@preact/preset-vite/dist/cjs/utils.js generated vendored Normal file
View File

@@ -0,0 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseId = exports.createFilter = void 0;
var pluginutils_1 = require("@rollup/pluginutils");
Object.defineProperty(exports, "createFilter", { enumerable: true, get: function () { return pluginutils_1.createFilter; } });
// Allows to ignore query parameters, as in Vue SFC virtual modules.
function parseId(url) {
return { id: url.split("?", 2)[0] };
}
exports.parseId = parseId;

View File

@@ -0,0 +1,8 @@
import { Plugin } from "vite";
import type { RollupFilter } from "./utils.mjs";
export interface PreactDevtoolsPluginOptions {
devtoolsInProd?: boolean;
devToolsEnabled?: boolean;
shouldTransform: RollupFilter;
}
export declare function preactDevtoolsPlugin({ devtoolsInProd, devToolsEnabled, shouldTransform, }: PreactDevtoolsPluginOptions): Plugin;

50
node_modules/@preact/preset-vite/dist/esm/devtools.mjs generated vendored Normal file
View File

@@ -0,0 +1,50 @@
import { normalizePath } from "vite";
import path from "path";
import debug from "debug";
import * as kl from "kolorist";
import { parseId } from "./utils.mjs";
export function preactDevtoolsPlugin({ devtoolsInProd, devToolsEnabled, shouldTransform, }) {
const log = debug("vite:preact-devtools");
let entry = "";
let config;
let found = false;
const plugin = {
name: "preact:devtools",
// Ensure that we resolve before everything else
enforce: "pre",
config() {
return {
optimizeDeps: {
include: ["preact/debug", "preact/devtools"],
},
};
},
configResolved(resolvedConfig) {
config = resolvedConfig;
devToolsEnabled =
devToolsEnabled !== null && devToolsEnabled !== void 0 ? devToolsEnabled : (!config.isProduction || devtoolsInProd);
},
resolveId(url, importer = "") {
const { id } = parseId(url);
// Get the main entry file to inject into
if (!found && /\.html$/.test(importer) && shouldTransform(id)) {
found = true;
entry = normalizePath(path.join(config.root, id));
// TODO: Vite types require explicit return
// undefined here. They're lacking the "void" type
// in their declarations
return undefined;
}
},
transform(code, url) {
const { id } = parseId(url);
if (entry === id && (!config.isProduction || devToolsEnabled)) {
const source = config.isProduction ? "preact/devtools" : "preact/debug";
code = `import "${source}";\n${code}`;
log(`[inject] ${kl.cyan(source)} -> ${kl.dim(id)}`);
return code;
}
},
};
return plugin;
}

83
node_modules/@preact/preset-vite/dist/esm/index.d.mts generated vendored Normal file
View File

@@ -0,0 +1,83 @@
import type { Plugin } from "vite";
import type { FilterPattern } from "@rollup/pluginutils";
import type { ParserOptions } from "@babel/parser";
import type { TransformOptions } from "@babel/core";
export type BabelOptions = Omit<TransformOptions, "ast" | "filename" | "root" | "sourceFileName" | "sourceMaps" | "inputSourceMap">;
export interface PreactPluginOptions {
/**
* Inject devtools bridge in production bundle instead of only in development mode.
* @default false
*/
devtoolsInProd?: boolean;
/**
* Whether to use Preact devtools
* @default true
*/
devToolsEnabled?: boolean;
/**
* Whether to use prefresh HMR
* @default true
*/
prefreshEnabled?: boolean;
/**
* Whether to alias react, react-dom to preact/compat
* @default true
*/
reactAliasesEnabled?: boolean;
/**
* Prerender plugin options
*/
prerender?: {
/**
* Whether to prerender your app on build
*/
enabled: boolean;
/**
* Absolute path to script containing an exported `prerender()` function
*/
prerenderScript?: string;
/**
* Query selector for specifying where to insert prerender result in your HTML template
*/
renderTarget?: string;
/**
* Additional routes that should be prerendered
*/
additionalPrerenderRoutes?: string[];
/**
* Vite's preview server won't use our prerendered HTML by default, this middleware correct this
*/
previewMiddlewareEnabled?: boolean;
/**
* Path to use as a fallback/404 route, i.e., `/404` or `/not-found`
*/
previewMiddlewareFallback?: string;
};
/**
* RegExp or glob to match files to be transformed
*/
include?: FilterPattern;
/**
* RegExp or glob to match files to NOT be transformed
*/
exclude?: FilterPattern;
/**
* Babel configuration applied in both dev and prod.
*/
babel?: BabelOptions;
/**
* Import Source for jsx. Defaults to "preact".
*/
jsxImportSource?: string;
}
export interface PreactBabelOptions extends BabelOptions {
plugins: Extract<BabelOptions["plugins"], any[]>;
presets: Extract<BabelOptions["presets"], any[]>;
overrides: Extract<BabelOptions["overrides"], any[]>;
parserOpts: ParserOptions & {
plugins: Extract<ParserOptions["plugins"], any[]>;
};
}
declare function preactPlugin({ devtoolsInProd, devToolsEnabled, prefreshEnabled, reactAliasesEnabled, prerender, include, exclude, babel, jsxImportSource, }?: PreactPluginOptions): Plugin[];
export default preactPlugin;
export { preactPlugin as preact };

169
node_modules/@preact/preset-vite/dist/esm/index.mjs generated vendored Normal file
View File

@@ -0,0 +1,169 @@
import prefresh from "@prefresh/vite";
import { preactDevtoolsPlugin } from "./devtools.mjs";
import { createFilter, parseId } from "./utils.mjs";
import { vitePrerenderPlugin } from "vite-prerender-plugin";
import { transformAsync } from "@babel/core";
// @ts-ignore package doesn't ship with declaration files
import babelReactJsx from "@babel/plugin-transform-react-jsx";
// @ts-ignore package doesn't ship with declaration files
import babelReactJsxDev from "@babel/plugin-transform-react-jsx-development";
// @ts-ignore package doesn't ship with declaration files
import babelHookNames from "babel-plugin-transform-hook-names";
// Taken from https://github.com/vitejs/vite/blob/main/packages/plugin-react/src/index.ts
function preactPlugin({ devtoolsInProd, devToolsEnabled, prefreshEnabled, reactAliasesEnabled, prerender, include, exclude, babel, jsxImportSource, } = {}) {
var _a;
const baseParserOptions = [
"importMeta",
"explicitResourceManagement",
"topLevelAwait",
];
let config;
let babelOptions = {
babelrc: false,
configFile: false,
...babel,
};
babelOptions.plugins || (babelOptions.plugins = []);
babelOptions.presets || (babelOptions.presets = []);
babelOptions.overrides || (babelOptions.overrides = []);
babelOptions.parserOpts || (babelOptions.parserOpts = {});
(_a = babelOptions.parserOpts).plugins || (_a.plugins = []);
let useBabel = typeof babel !== "undefined";
const shouldTransform = createFilter(include || [/\.[cm]?[tj]sx?$/], exclude || [/node_modules/]);
devtoolsInProd = devtoolsInProd !== null && devtoolsInProd !== void 0 ? devtoolsInProd : false;
prefreshEnabled = prefreshEnabled !== null && prefreshEnabled !== void 0 ? prefreshEnabled : true;
reactAliasesEnabled = reactAliasesEnabled !== null && reactAliasesEnabled !== void 0 ? reactAliasesEnabled : true;
prerender = prerender !== null && prerender !== void 0 ? prerender : { enabled: false };
const prerenderPlugin = vitePrerenderPlugin(prerender);
if (!prerender.previewMiddlewareEnabled) {
const idx = prerenderPlugin.findIndex(p => p.name == "serve-prerendered-html");
if (idx > -1) {
prerenderPlugin.splice(idx, 1);
}
}
const jsxPlugin = {
name: "vite:preact-jsx",
enforce: "pre",
config() {
return {
build: {
rollupOptions: {
onwarn(warning, warn) {
// Silence Rollup's module-level directive warnings re:"use client".
// They're likely to come from `node_modules` and won't be actionable.
if (warning.code === "MODULE_LEVEL_DIRECTIVE" &&
warning.message.includes("use client"))
return;
// ESBuild seemingly doesn't include mappings for directives, causing
// Rollup to emit warnings about missing source locations. This too is
// likely to come from `node_modules` and won't be actionable.
// evanw/esbuild#3548
if (warning.code === "SOURCEMAP_ERROR" &&
warning.message.includes("resolve original location") &&
warning.pos === 0)
return;
warn(warning);
},
},
},
esbuild: useBabel
? undefined
: {
jsx: "automatic",
jsxImportSource: jsxImportSource !== null && jsxImportSource !== void 0 ? jsxImportSource : "preact",
},
optimizeDeps: {
include: ["preact", "preact/jsx-runtime", "preact/jsx-dev-runtime"],
},
};
},
configResolved(resolvedConfig) {
config = resolvedConfig;
devToolsEnabled =
devToolsEnabled !== null && devToolsEnabled !== void 0 ? devToolsEnabled : (!config.isProduction || devtoolsInProd);
useBabel || (useBabel = !config.isProduction || !!devToolsEnabled);
},
async transform(code, url) {
// Ignore query parameters, as in Vue SFC virtual modules.
const { id } = parseId(url);
if (!useBabel || !shouldTransform(id))
return;
const parserPlugins = [
...baseParserOptions,
"classProperties",
"classPrivateProperties",
"classPrivateMethods",
!id.endsWith(".ts") && "jsx",
/\.tsx?$/.test(id) && "typescript",
].filter(Boolean);
const result = await transformAsync(code, {
...babelOptions,
ast: true,
root: config.root,
filename: id,
parserOpts: {
...babelOptions.parserOpts,
sourceType: "module",
allowAwaitOutsideFunction: true,
plugins: parserPlugins,
},
generatorOpts: {
...babelOptions.generatorOpts,
decoratorsBeforeExport: true,
},
plugins: [
...babelOptions.plugins,
[
config.isProduction ? babelReactJsx : babelReactJsxDev,
{
runtime: "automatic",
importSource: jsxImportSource !== null && jsxImportSource !== void 0 ? jsxImportSource : "preact",
},
],
...(devToolsEnabled ? [babelHookNames] : []),
],
sourceMaps: true,
inputSourceMap: false,
});
// NOTE: Since no config file is being loaded, this path wouldn't occur.
if (!result)
return;
return {
code: result.code || code,
map: result.map,
};
},
};
return [
...(reactAliasesEnabled
? [
{
name: "preact:config",
config() {
return {
resolve: {
alias: {
"react-dom/test-utils": "preact/test-utils",
"react-dom": "preact/compat",
react: "preact/compat",
},
},
};
},
},
]
: []),
jsxPlugin,
preactDevtoolsPlugin({
devtoolsInProd,
devToolsEnabled,
shouldTransform,
}),
...(prefreshEnabled
? [prefresh({ include, exclude, parserPlugins: baseParserOptions })]
: []),
...(prerender.enabled ? prerenderPlugin : []),
];
}
export default preactPlugin;
export { preactPlugin as preact };

View File

@@ -0,0 +1,6 @@
import type { CreateFilter } from "@rollup/pluginutils";
export { createFilter } from "@rollup/pluginutils";
export type RollupFilter = ReturnType<CreateFilter>;
export declare function parseId(url: string): {
id: string;
};

5
node_modules/@preact/preset-vite/dist/esm/utils.mjs generated vendored Normal file
View File

@@ -0,0 +1,5 @@
export { createFilter } from "@rollup/pluginutils";
// Allows to ignore query parameters, as in Vue SFC virtual modules.
export function parseId(url) {
return { id: url.split("?", 2)[0] };
}

88
node_modules/@preact/preset-vite/package.json generated vendored Normal file
View File

@@ -0,0 +1,88 @@
{
"name": "@preact/preset-vite",
"version": "2.10.1",
"description": "Preact preset for the vite bundler",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.mjs",
"exports": {
".": {
"import": "./dist/esm/index.mjs",
"require": "./dist/cjs/index.js"
},
"./package.json": "./package.json"
},
"types": "dist/cjs/index.d.ts",
"scripts": {
"dev": "vite demo",
"dev:build": "vite build demo",
"dev:preview": "vite preview demo",
"build": "rimraf dist && tsc && tsc -p tsconfig.cjs.json && node tools/postbuild.mjs",
"test": "rimraf demo/node_modules && node --test test",
"prepublishOnly": "npm run build"
},
"keywords": [
"preact",
"vite",
"vite-preset",
"preset"
],
"author": "The Preact Team (https://preactjs.com)",
"repository": {
"type": "git",
"url": "git+https://github.com/preactjs/preset-vite.git"
},
"license": "MIT",
"files": [
"dist/"
],
"dependencies": {
"@babel/plugin-transform-react-jsx": "^7.22.15",
"@babel/plugin-transform-react-jsx-development": "^7.22.5",
"@prefresh/vite": "^2.4.1",
"@rollup/pluginutils": "^4.1.1",
"babel-plugin-transform-hook-names": "^1.0.2",
"debug": "^4.3.4",
"kolorist": "^1.8.0",
"vite-prerender-plugin": "^0.5.3"
},
"peerDependencies": {
"@babel/core": "7.x",
"vite": "2.x || 3.x || 4.x || 5.x || 6.x"
},
"devDependencies": {
"@babel/core": "^7.15.8",
"@types/babel__code-frame": "^7.0.6",
"@types/babel__core": "^7.1.14",
"@types/debug": "^4.1.5",
"@types/estree": "^0.0.50",
"@types/node": "^14.14.33",
"@types/stack-trace": "^0.0.33",
"lint-staged": "^10.5.4",
"preact": "^10.19.2",
"preact-iso": "^2.3.2",
"preact-render-to-string": "^6.3.1",
"prettier": "^2.2.1",
"rimraf": "^3.0.2",
"rollup": "^2.77.3",
"simple-git-hooks": "^2.0.2",
"ts-node": "^9.1.1",
"typescript": "^4.2.3",
"vite": "^2.6.7"
},
"lint-staged": {
"**/*.{js,jsx,ts,tsx,yml,json}": [
"prettier --write"
]
},
"simple-git-hooks": {
"pre-commit": "npx lint-staged"
},
"prettier": {
"useTabs": true,
"arrowParens": "avoid",
"trailingComma": "all"
},
"volta": {
"node": "18.12.1"
}
}