{"version":3,"sources":["../src/webpackFinal.ts","../src/preset.ts"],"names":["logger","colors","isRuleForStyles","rule","webpackFinal","config","rules","plugins"],"mappings":"AAAA,OAAS,UAAAA,EAAQ,UAAAC,MAAc,yBAIxB,IAAMC,EAAmBC,GAC9BA,EAAK,gBAAgB,SACpBA,EAAK,KAAK,KAAK,UAAU,GACxBA,EAAK,KAAK,KAAK,WAAW,GAC1BA,EAAK,KAAK,KAAK,WAAW,GAEvB,SAASC,EACdC,EACA,CAAE,MAAAC,EAAO,QAAAC,CAAQ,EAAyB,CAAC,EAC3C,CAgBA,GAfAP,EAAO,KACL,OAAOC,EAAO,KAAK,KACjB,0BACF,6DACF,EACIM,GAAWA,EAAQ,SACrBP,EAAO,KACL,OAAOC,EAAO,KAAK,KACjB,0BACF,6DACF,EACAI,EAAO,QAAUA,EAAO,SAAW,CAAC,EACpCA,EAAO,QAAQ,KAAK,GAAGE,CAAO,GAG5BD,GAASA,EAAM,OAAQ,CAOzB,GANAN,EAAO,KACL,OAAOC,EAAO,KAAK,KACjB,0BACF,qEACF,EAEI,CAACI,EAAO,QAAQ,MAClB,MAAM,IAAI,MACR,8EACF,EAIFA,EAAO,OAAO,MAAQA,EAAO,OAAO,MAAM,OACvCF,GAAS,OAAOA,GAAS,UAAY,CAACD,EAAgBC,CAAI,CAC7D,EAGAE,EAAO,OAAO,OAAO,KAAK,GAAGC,CAAK,EAGpC,OAAOD,CACT,CClDO,IAAMD,EAAeA","sourcesContent":["import { logger, colors } from \"@storybook/node-logger\";\nimport type { RuleSetRule, Configuration as WebpackConfig } from \"webpack\";\nimport type { AddonStylingOptions } from \"./types\";\n\nexport const isRuleForStyles = (rule: RuleSetRule) =>\n rule.test instanceof RegExp &&\n (rule.test.test(\"test.css\") ||\n rule.test.test(\"test.scss\") ||\n rule.test.test(\"test.less\"));\n\nexport function webpackFinal(\n config: WebpackConfig,\n { rules, plugins }: AddonStylingOptions = {}\n) {\n logger.info(\n `=> [${colors.pink.bold(\n \"@storybook/addon-styling\"\n )}] Applying custom Storybook webpack configuration styling.`\n );\n if (plugins && plugins.length) {\n logger.info(\n `=> [${colors.pink.bold(\n \"@storybook/addon-styling\"\n )}] Adding given plugins to Storybook webpack configuration.`\n );\n config.plugins = config.plugins || [];\n config.plugins.push(...plugins);\n }\n\n if (rules && rules.length) {\n logger.info(\n `=> [${colors.pink.bold(\n \"@storybook/addon-styling\"\n )}] Replacing Storybook's webpack rules for styles with given rules.`\n );\n\n if (!config.module?.rules) {\n throw new Error(\n \"webpackFinal received a rules option but config.module.rules is not an array\"\n );\n }\n\n // Remove any existing rules for styles\n config.module.rules = config.module.rules.filter(\n (rule) => typeof rule === \"object\" && !isRuleForStyles(rule)\n );\n\n // Add the new rules for styles\n config.module.rules?.push(...rules);\n }\n\n return config;\n}\n","import { webpackFinal as webpack } from \"./webpackFinal\";\n\nexport const webpackFinal = webpack as any;\n"]}