UNPKG

@lynx-js/qrcode-rsbuild-plugin

Version:

A rsbuild plugin for printing QRCode in terminal

95 lines (94 loc) 2.52 kB
/** * @packageDocumentation * * A rsbuild plugin that print the template.js url using QRCode. */ import type { RsbuildPlugin } from '@rsbuild/core'; /** * {@inheritdoc PluginQRCodeOptions.schema} * * @public */ export type CustomizedSchemaFn = (url: string) => string | Record<string, string>; /** * The options for {@link pluginQRCode}. * * @public */ export interface PluginQRCodeOptions { /** * Customize the generated schema. * * @example * * ```js * import { pluginQRCode } from '@lynx-js/qrcode-rsbuild-plugin' * import { defineConfig } from '@lynx-js/rspeedy' * * export default defineConfig({ * plugins: [ * pluginQRCode({ * schema(url) { * return `lynx://${url}?dev=1` * }, * }), * ], * }) * ``` * * @example * * - Use multiple schemas: * * You may press `a` in the terminal to switch between schemas. * * ```js * import { pluginQRCode } from '@lynx-js/qrcode-rsbuild-plugin' * import { defineConfig } from '@lynx-js/rspeedy' * * export default defineConfig({ * plugins: [ * pluginQRCode({ * schema(url) { * return { * http: url, * foo: `foo://lynx?url=${encodeURIComponent(url)}&dev=1`, * bar: `bar://lynx?url=${encodeURIComponent(url)}`, * } * }, * }), * ], * }) * ``` */ schema?: CustomizedSchemaFn | undefined; /** * Opt in to the fullscreen variant of the Lynx bundle URL (appends * `?fullscreen=true`, opening the bundle in LynxExplorer with the in-app * navigation chrome stripped). * * When enabled, the plugin: * - Appends a `fullscreen` entry to the schema rotation — the QR keeps * opening on your default schema; press `a` in the dev console to switch * to the `fullscreen` variant. * - Appends an `∟ Fullscreen` URL line under each Lynx bundle URL printed * by the dev server. * * @defaultValue `false` */ fullscreen?: boolean | undefined; } /** * Create a rsbuild plugin for printing QRCode. * * @example * ```ts * // rsbuild.config.ts * import { pluginQRCode } from '@lynx-js/qrcode-rsbuild-plugin' * export default { * plugins: [pluginQRCode()], * } * ``` * * @public */ export declare function pluginQRCode(options?: PluginQRCodeOptions): RsbuildPlugin;