Skip to content

Commit

Permalink
Update Storybook's configuration of Vite to wrap cascade layers aroun…
Browse files Browse the repository at this point in the history
…d the imported LESS files.
  • Loading branch information
Mark Fitzgerald committed Jan 17, 2025
1 parent 908d55b commit 9c2bed1
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,24 @@ import {mergeConfig} from "vite";

import type {StorybookConfig} from "@storybook/react-vite";

// This is a temporary plugin option to mimic what is in PROD in regard to cascade layers.
// Perseus LESS files are wrapped in the 'shared' layer in Webapp.
// To get the same ordering of precedence in Storybook, the imported LESS files need to be wrapped accordingly.
// Once the LESS files have cascade layers included (a more involved task for a later time),
// then the following plugin option should be removed.
const lessWrapper = {
name: 'wrap-less-in-layer',
transform: (code: string, pathname: string) => {
if (pathname.endsWith(".less")) {
const layerStatements = "@layer reset, shared, legacy;\n@layer shared";
return {
code: `${layerStatements} { ${code} }`,
map: null,
}
}
}
};

const config: StorybookConfig = {
framework: "@storybook/react-vite",

Expand Down Expand Up @@ -53,6 +71,7 @@ const config: StorybookConfig = {
},
// Fix from: https://github.com/storybookjs/storybook/issues/25256#issuecomment-1866441206
assetsInclude: ["/sb-preview/runtime.js"],
plugins: [...viteConfig.plugins, lessWrapper],
});
},
staticDirs: ["../static"],
Expand Down

0 comments on commit 9c2bed1

Please sign in to comment.