diff --git a/.storybook/main.ts b/.storybook/main.ts index 68fc619..e2a56fe 100644 --- a/.storybook/main.ts +++ b/.storybook/main.ts @@ -6,7 +6,9 @@ const config: StorybookConfig = { "@storybook/addon-essentials", { name: "./local-preset.js", - options: {}, + options: { + less: {}, + }, }, ], framework: { diff --git a/package.json b/package.json index 284c61e..4dfe6de 100644 --- a/package.json +++ b/package.json @@ -67,6 +67,7 @@ "@storybook/components": "^7.0.2", "@storybook/core-events": "^7.0.2", "@storybook/manager-api": "^7.0.2", + "@storybook/node-logger": "^7.0.7", "@storybook/preview-api": "^7.0.2", "@storybook/theming": "^7.0.2", "@storybook/types": "^7.0.2", diff --git a/src/preset.ts b/src/preset.ts index 5cf4755..806e311 100644 --- a/src/preset.ts +++ b/src/preset.ts @@ -1,3 +1,6 @@ import { webpackFinal as webpack } from "./webpack/webpackFinal"; +import { viteFinal as vite } from "./vite/viteFinal"; export const webpackFinal = webpack as any; + +export const viteFinal = vite as any; diff --git a/src/webpack/types.ts b/src/types.ts similarity index 100% rename from src/webpack/types.ts rename to src/types.ts diff --git a/src/vite/viteFinal.ts b/src/vite/viteFinal.ts new file mode 100644 index 0000000..1479068 --- /dev/null +++ b/src/vite/viteFinal.ts @@ -0,0 +1,59 @@ +import { logger, colors } from "@storybook/node-logger"; +import type { AddonStylingOptions } from "../types"; + +export function viteFinal(config: any, options: AddonStylingOptions = {}) { + if (options.cssModules) { + logger.warn( + `[@storybook/addon-styling] "${colors.blue( + "options.cssModules" + )}" is for webpack only. Vite comes preconfigured with css-module support.` + ); + } + if (options.cssBuildRule) { + logger.warn( + `[@storybook/addon-styling] "${colors.blue( + "options.cssBuildRule" + )}" is for webpack only. To customize your CSS build, update your Vite config.` + ); + } + + if (options.postCss) { + logger.warn( + `[@storybook/addon-styling] "${colors.blue( + "options.postCss" + )}" is for webpack only. Vite comes preconfigured with PostCSS support.` + ); + } + + if (options.sass) { + logger.warn( + `[@storybook/addon-styling] "${colors.blue( + "options.sass" + )}" is for webpack only. Vite comes preconfigured with Sass/Scss support.` + ); + } + if (options.scssBuildRule) { + logger.warn( + `[@storybook/addon-styling] "${colors.blue( + "options.scssBuildRule" + )}" is for webpack only. Vite comes preconfigured with Sass/Scss support.` + ); + } + + if (options.less) { + logger.warn( + `[@storybook/addon-styling] "${colors.blue( + "options.less" + )}" is for webpack only. Vite comes preconfigured with Less support.` + ); + } + if (options.lessBuildRule) { + logger.warn( + `[@storybook/addon-styling] "${colors.blue( + "options.lessBuildRule" + )}" is for webpack only. Vite comes preconfigured with Less support.` + ); + } + + return config; +} diff --git a/src/webpack/css/webpack.ts b/src/webpack/css/webpack.ts index 5ab738c..91b194b 100644 --- a/src/webpack/css/webpack.ts +++ b/src/webpack/css/webpack.ts @@ -1,5 +1,5 @@ import type { RuleSetRule, Configuration as WebpackConfig } from "webpack"; -import type { AddonStylingOptions } from "../types"; +import type { AddonStylingOptions } from "../../types"; const isRuleForCSS = (rule: RuleSetRule) => typeof rule !== "string" && diff --git a/src/webpack/less/webpack.ts b/src/webpack/less/webpack.ts index a9c9ece..b30dac3 100644 --- a/src/webpack/less/webpack.ts +++ b/src/webpack/less/webpack.ts @@ -1,5 +1,5 @@ import type { RuleSetRule, Configuration as WebpackConfig } from "webpack"; -import type { AddonStylingOptions } from "../types"; +import type { AddonStylingOptions } from "../../types"; const isRuleForLESS = (rule: RuleSetRule) => typeof rule !== "string" && diff --git a/src/webpack/scss/webpack.ts b/src/webpack/scss/webpack.ts index 0efa6ea..8256676 100644 --- a/src/webpack/scss/webpack.ts +++ b/src/webpack/scss/webpack.ts @@ -1,5 +1,5 @@ import type { RuleSetRule, Configuration as WebpackConfig } from "webpack"; -import type { AddonStylingOptions } from "../types"; +import type { AddonStylingOptions } from "../../types"; const isRuleForSCSS = (rule: RuleSetRule) => typeof rule !== "string" && diff --git a/src/webpack/webpackFinal.ts b/src/webpack/webpackFinal.ts index 9631083..ad6b86e 100644 --- a/src/webpack/webpackFinal.ts +++ b/src/webpack/webpackFinal.ts @@ -1,5 +1,5 @@ import type { Configuration as WebpackConfig } from "webpack"; -import type { AddonStylingOptions } from "./types"; +import type { AddonStylingOptions } from "../types"; import { patchOrAddCssRule } from "./css/webpack"; import { patchOrAddScssRule } from "./scss/webpack"; diff --git a/yarn.lock b/yarn.lock index c245a6b..be103f7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3163,6 +3163,16 @@ npmlog "^5.0.1" pretty-hrtime "^1.0.3" +"@storybook/node-logger@^7.0.7": + version "7.0.7" + resolved "https://registry.yarnpkg.com/@storybook/node-logger/-/node-logger-7.0.7.tgz#114e6d1994e0445dd9e579768bdb89adbf1055cd" + integrity sha512-5Y4LLgKeCStq1ktCKZ5eNPzQQSQ+CYZAlkEdzQ3Pp//0KXaZvVxEvGtaYhAymP2HatLpI8Oneo4lHrJioRfgww== + dependencies: + "@types/npmlog" "^4.1.2" + chalk "^4.1.0" + npmlog "^5.0.1" + pretty-hrtime "^1.0.3" + "@storybook/postinstall@7.0.2": version "7.0.2" resolved "https://registry.yarnpkg.com/@storybook/postinstall/-/postinstall-7.0.2.tgz#cccbecb5a52ef0797d72fd919f024d785b1fb8d6"