UNPKG

@storybook/addon-styling-webpack

Version:

A base addon for configuring popular styling tools in Webpack

51 lines (46 loc) 2.48 kB
import { __commonJS, __toESM } from './chunk-JSBRDJBE.js'; import { logger } from 'storybook/internal/node-logger'; // node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.browser.js var require_picocolors_browser = __commonJS({ "node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.browser.js"(exports, module) { var x = String; var create = function() { return { isColorSupported: false, reset: x, bold: x, dim: x, italic: x, underline: x, inverse: x, hidden: x, strikethrough: x, black: x, red: x, green: x, yellow: x, blue: x, magenta: x, cyan: x, white: x, gray: x, bgBlack: x, bgRed: x, bgGreen: x, bgYellow: x, bgBlue: x, bgMagenta: x, bgCyan: x, bgWhite: x, blackBright: x, redBright: x, greenBright: x, yellowBright: x, blueBright: x, magentaBright: x, cyanBright: x, whiteBright: x, bgBlackBright: x, bgRedBright: x, bgGreenBright: x, bgYellowBright: x, bgBlueBright: x, bgMagentaBright: x, bgCyanBright: x, bgWhiteBright: x }; }; module.exports = create(); module.exports.createColors = create; } }); // src/webpackFinal.ts var import_picocolors = __toESM(require_picocolors_browser(), 1); var isRuleForStyles = (rule) => rule.test instanceof RegExp && (rule.test.test("test.css") || rule.test.test("test.scss") || rule.test.test("test.less")); function webpackFinal(config, { rules, plugins } = {}) { logger.info( `=> [${import_picocolors.default.green("@storybook/addon-styling-webpack")}] Applying custom Storybook webpack configuration styling.` ); if (plugins && plugins.length) { logger.info( `=> [${import_picocolors.default.green("@storybook/addon-styling-webpack")}] Adding given plugins to Storybook webpack configuration.` ); config.plugins = config.plugins || []; config.plugins.push(...plugins); } if (rules && rules.length) { logger.info( `=> [${import_picocolors.default.green( "@storybook/addon-styling-webpack" )}] Replacing Storybook's webpack rules for styles with given rules.` ); if (!config.module?.rules) { throw new Error("webpackFinal received a rules option but config.module.rules is not an array"); } config.module.rules = config.module.rules.filter( (rule) => typeof rule === "object" && rule && !isRuleForStyles(rule) ); config.module.rules?.push(...rules); } return config; } // src/preset.ts var webpackFinal2 = webpackFinal; export { webpackFinal2 as webpackFinal };