UNPKG

@lynx-js/qrcode-rsbuild-plugin

Version:

A rsbuild plugin for printing QRCode in terminal

80 lines (79 loc) 1.9 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; } /** * 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;