Init
This commit is contained in:
8
node_modules/@preact/preset-vite/dist/esm/devtools.d.mts
generated
vendored
Normal file
8
node_modules/@preact/preset-vite/dist/esm/devtools.d.mts
generated
vendored
Normal 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
50
node_modules/@preact/preset-vite/dist/esm/devtools.mjs
generated
vendored
Normal 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
83
node_modules/@preact/preset-vite/dist/esm/index.d.mts
generated
vendored
Normal 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
169
node_modules/@preact/preset-vite/dist/esm/index.mjs
generated
vendored
Normal 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 };
|
6
node_modules/@preact/preset-vite/dist/esm/utils.d.mts
generated
vendored
Normal file
6
node_modules/@preact/preset-vite/dist/esm/utils.d.mts
generated
vendored
Normal 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
5
node_modules/@preact/preset-vite/dist/esm/utils.mjs
generated
vendored
Normal 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] };
|
||||
}
|
Reference in New Issue
Block a user