UNPKG

@storybook/preset-react-webpack

Version:

Storybook for React: Develop React Component in isolation with Hot Reloading

73 lines (69 loc) 2.46 kB
import CJS_COMPAT_NODE_URL_yhv20ho0s6p from 'node:url'; import CJS_COMPAT_NODE_PATH_yhv20ho0s6p from 'node:path'; import CJS_COMPAT_NODE_MODULE_yhv20ho0s6p from "node:module"; var __filename = CJS_COMPAT_NODE_URL_yhv20ho0s6p.fileURLToPath(import.meta.url); var __dirname = CJS_COMPAT_NODE_PATH_yhv20ho0s6p.dirname(__filename); var require = CJS_COMPAT_NODE_MODULE_yhv20ho0s6p.createRequire(import.meta.url); // ------------------------------------------------------------ // end of CJS compatibility banner, injected by Storybook's esbuild configuration // ------------------------------------------------------------ // src/framework-preset-react-docs.ts import { fileURLToPath } from "node:url"; var webpackFinal = async (config, options) => { let typescriptOptions = await options.presets.apply("typescript", {}), debug = options.loglevel === "debug", { reactDocgen, reactDocgenTypescriptOptions } = typescriptOptions || {}; if (typeof reactDocgen != "string") return config; if (reactDocgen !== "react-docgen-typescript") return { ...config, module: { ...config.module ?? {}, rules: [ ...config.module?.rules ?? [], { test: /\.(cjs|mjs|tsx?|jsx?)$/, enforce: "pre", loader: fileURLToPath( import.meta.resolve("@storybook/preset-react-webpack/react-docgen-loader") ), options: { debug }, exclude: /(\.(stories|story)\.(js|jsx|ts|tsx))|(node_modules)/ } ] } }; let { ReactDocgenTypeScriptPlugin } = await import("@storybook/react-docgen-typescript-plugin"); return { ...config, module: { ...config.module ?? {}, rules: [ ...config.module?.rules ?? [], { test: /\.(cjs|mjs|jsx?)$/, enforce: "pre", loader: fileURLToPath( import.meta.resolve("@storybook/preset-react-webpack/react-docgen-loader") ), options: { debug }, exclude: /(\.(stories|story)\.(js|jsx|ts|tsx))|(node_modules)/ } ] }, plugins: [ ...config.plugins || [], new ReactDocgenTypeScriptPlugin({ ...reactDocgenTypescriptOptions, // We *need* this set so that RDT returns default values in the same format as react-docgen savePropValueAsString: !0 }) ] }; }; export { webpackFinal };