|
1 | 1 | import type { StorybookConfig } from "@storybook/nextjs"; |
2 | 2 |
|
3 | | -import { join, dirname } from "path"; |
| 3 | +import { dirname } from "path"; |
4 | 4 | import { resolve } from "path"; |
| 5 | +import { fileURLToPath } from "url"; |
5 | 6 | import dotenv from "dotenv"; |
6 | 7 |
|
| 8 | +const __filename = fileURLToPath(import.meta.url); |
| 9 | +const __dirname = dirname(__filename); |
| 10 | + |
7 | 11 | dotenv.config({ |
8 | 12 | path: resolve(__dirname, "../.env.local"), |
9 | 13 | }); |
10 | 14 |
|
11 | | -/** |
12 | | - * This function is used to resolve the absolute path of a package. |
13 | | - * It is needed in projects that use Yarn PnP or are set up within a monorepo. |
14 | | - */ |
15 | | -function getAbsolutePath(value: string): any { |
16 | | - return dirname(require.resolve(join(value, "package.json"))); |
17 | | -} |
18 | 15 | const config: StorybookConfig = { |
19 | 16 | stories: [ |
20 | 17 | "../stories/**/*.mdx", |
21 | 18 | "../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)", |
22 | 19 | "../shared/**/*.stories.@(js|jsx|mjs|ts|tsx)", |
23 | 20 | ], |
24 | 21 | addons: [ |
25 | | - getAbsolutePath("@storybook/addon-onboarding"), |
26 | | - getAbsolutePath("@chromatic-com/storybook"), |
27 | | - getAbsolutePath("@storybook/addon-vitest"), |
28 | | - getAbsolutePath("@storybook/addon-designs"), |
| 22 | + "@storybook/addon-onboarding", |
| 23 | + "@chromatic-com/storybook", |
| 24 | + "@storybook/addon-vitest", |
| 25 | + "@storybook/addon-designs", |
29 | 26 | ], |
30 | | - framework: getAbsolutePath("@storybook/nextjs"), |
| 27 | + framework: { |
| 28 | + name: "@storybook/nextjs", |
| 29 | + options: {}, |
| 30 | + }, |
31 | 31 | staticDirs: ["../public"], |
32 | 32 |
|
33 | | - webpackFinal: async (config) => { |
34 | | - // Fix for Next.js 15 compatibility with Storybook |
35 | | - // Disable persistent caching to avoid webpack hook issues |
36 | | - config.cache = false; |
37 | | - |
38 | | - // Disable infrastructureLogging errors |
39 | | - if (config.infrastructureLogging) { |
40 | | - config.infrastructureLogging.level = "error"; |
41 | | - } |
42 | | - |
43 | | - // Fix circular dependency issues in production builds |
44 | | - config.optimization = { |
45 | | - ...config.optimization, |
46 | | - moduleIds: "named", |
47 | | - chunkIds: "named", |
48 | | - mangleExports: false, |
49 | | - minimize: false, |
50 | | - }; |
51 | | - |
52 | | - // Inject Figma env variables into browser bundle for Storybook addon-designs |
53 | | - const webpack = require("webpack"); |
54 | | - config.plugins = config.plugins || []; |
55 | | - |
56 | | - const figmaEnvVars: Record<string, string> = {}; |
57 | | - |
58 | | - if (process.env.FIGMA_TOKEN) { |
59 | | - figmaEnvVars["process.env.FIGMA_TOKEN"] = JSON.stringify( |
60 | | - process.env.FIGMA_TOKEN |
61 | | - ); |
62 | | - } else { |
63 | | - console.warn("⚠️ FIGMA_TOKEN not found"); |
64 | | - } |
65 | | - |
66 | | - if (process.env.FIGMA_FILE_URL) { |
67 | | - figmaEnvVars["process.env.FIGMA_FILE_URL"] = JSON.stringify( |
68 | | - process.env.FIGMA_FILE_URL |
69 | | - ); |
70 | | - } else { |
71 | | - console.warn("⚠️ FIGMA_FILE_URL not found"); |
72 | | - } |
73 | | - |
74 | | - if (Object.keys(figmaEnvVars).length > 0) { |
75 | | - config.plugins.push(new webpack.DefinePlugin(figmaEnvVars)); |
76 | | - } |
77 | | - |
78 | | - return config; |
79 | | - }, |
| 33 | + env: (config) => ({ |
| 34 | + ...config, |
| 35 | + FIGMA_TOKEN: process.env.FIGMA_TOKEN || "", |
| 36 | + FIGMA_FILE_URL: process.env.FIGMA_FILE_URL || "", |
| 37 | + }), |
80 | 38 | }; |
| 39 | + |
81 | 40 | export default config; |
0 commit comments