|
| 1 | +const path = require("path"); |
| 2 | +const webpack = require("webpack"); |
| 3 | + |
| 4 | +module.exports = { |
| 5 | + stories: ["../src/react-components/**/*.stories.mdx", "../src/react-components/**/*.stories.js", "../stories/**/*.stories.js"], |
| 6 | + addons: ["@storybook/addon-links", "@storybook/addon-docs"], |
| 7 | + staticDirs: ["../src/assets", "./static"], |
| 8 | + webpackFinal: async config => { |
| 9 | + // Improve stack traces: use high-quality source maps in dev, full source maps in build |
| 10 | + config.devtool = config.mode === "development" ? "eval-source-map" : "source-map"; |
| 11 | + |
| 12 | + // Name chunks/modules for more readable stacks |
| 13 | + config.optimization = { |
| 14 | + ...config.optimization, |
| 15 | + moduleIds: "named", |
| 16 | + chunkIds: "named" |
| 17 | + }; |
| 18 | + |
| 19 | + // Make sure source maps point to real files |
| 20 | + config.output = { |
| 21 | + ...config.output, |
| 22 | + devtoolModuleFilenameTemplate: info => { |
| 23 | + // Prefer absolute paths for better mapping in Chrome/Playwright logs |
| 24 | + return `webpack:///${info.resourcePath}`; |
| 25 | + } |
| 26 | + }; |
| 27 | + |
| 28 | + // Add explicit babel-loader rule for JS/JSX/TS/TSX files at the beginning |
| 29 | + config.module.rules.unshift({ |
| 30 | + test: /\.(js|jsx|ts|tsx)$/, |
| 31 | + exclude: /node_modules/, |
| 32 | + use: { |
| 33 | + loader: "babel-loader", |
| 34 | + options: { |
| 35 | + sourceMaps: true, |
| 36 | + presets: [ |
| 37 | + ["@babel/preset-env", { targets: "defaults" }], |
| 38 | + ["@babel/preset-react", { runtime: "automatic" }], |
| 39 | + "@babel/preset-typescript" |
| 40 | + ], |
| 41 | + plugins: [ |
| 42 | + "formatjs", |
| 43 | + ["@babel/plugin-proposal-private-property-in-object", { loose: true }], |
| 44 | + ["@babel/plugin-proposal-private-methods", { loose: true }] |
| 45 | + ] |
| 46 | + } |
| 47 | + } |
| 48 | + }); |
| 49 | + |
| 50 | + // Add SCSS support for admin styles |
| 51 | + config.module.rules.push({ |
| 52 | + test: /\.scss$/, |
| 53 | + use: [ |
| 54 | + "style-loader", |
| 55 | + { |
| 56 | + loader: "css-loader", |
| 57 | + options: { |
| 58 | + modules: false // Admin uses global styles |
| 59 | + } |
| 60 | + }, |
| 61 | + "sass-loader" |
| 62 | + ], |
| 63 | + include: [ |
| 64 | + path.resolve(__dirname, "..", "src"), |
| 65 | + path.resolve(__dirname, "..", "..", "src") // Access main hubs styles if needed |
| 66 | + ] |
| 67 | + }); |
| 68 | + |
| 69 | + // Handle SVG files |
| 70 | + const fileLoaderRule = config.module.rules.find(rule => rule.test && rule.test.test && rule.test.test(".svg")); |
| 71 | + if (fileLoaderRule) { |
| 72 | + fileLoaderRule.exclude = /\.svg$/; |
| 73 | + } |
| 74 | + |
| 75 | + config.module.rules.push({ |
| 76 | + test: /\.svg$/, |
| 77 | + use: ["@svgr/webpack", "url-loader"] |
| 78 | + }); |
| 79 | + |
| 80 | + // Handle other asset files - exclude PNG from file-loader to use static assets instead |
| 81 | + config.module.rules.push({ |
| 82 | + test: /\.(jpg|jpeg|gif|ico)$/, |
| 83 | + use: ["file-loader"], |
| 84 | + include: path.resolve(__dirname, "../") |
| 85 | + }); |
| 86 | + |
| 87 | + // Add DefinePlugin to provide process.env variables for admin |
| 88 | + config.plugins.push( |
| 89 | + new webpack.DefinePlugin({ |
| 90 | + "process.env": { |
| 91 | + NODE_ENV: JSON.stringify("development"), |
| 92 | + RETICULUM_SERVER: JSON.stringify(""), |
| 93 | + POSTGREST_SERVER: JSON.stringify(""), |
| 94 | + ITA_SERVER: JSON.stringify(""), |
| 95 | + BASE_ASSETS_PATH: JSON.stringify(""), |
| 96 | + STORYBOOK_APP_CONFIG: JSON.stringify("") |
| 97 | + } |
| 98 | + }) |
| 99 | + ); |
| 100 | + |
| 101 | + // Resolve admin node_modules and parent node_modules |
| 102 | + config.resolve.modules = [ |
| 103 | + path.resolve(__dirname, "..", "node_modules"), |
| 104 | + path.resolve(__dirname, "..", "..", "node_modules"), |
| 105 | + "node_modules" |
| 106 | + ]; |
| 107 | + |
| 108 | + // Mock problematic modules for Storybook |
| 109 | + config.resolve.alias = { |
| 110 | + ...config.resolve.alias, |
| 111 | + "../utils/configs": path.resolve(__dirname, "mocks", "configs.js"), |
| 112 | + "./configs": path.resolve(__dirname, "mocks", "configs.js"), |
| 113 | + "../utils/ita": path.resolve(__dirname, "mocks", "ita.js"), |
| 114 | + "./ita": path.resolve(__dirname, "mocks", "ita.js"), |
| 115 | + "../utils/feature_flags": path.resolve(__dirname, "mocks", "feature_flags.js"), |
| 116 | + "./feature_flags": path.resolve(__dirname, "mocks", "feature_flags.js") |
| 117 | + }; |
| 118 | + |
| 119 | + return config; |
| 120 | + }, |
| 121 | + framework: { |
| 122 | + name: "@storybook/react-webpack5", |
| 123 | + options: {} |
| 124 | + }, |
| 125 | + babel: async options => { |
| 126 | + return { |
| 127 | + ...options, |
| 128 | + presets: [...options.presets, ["@babel/preset-react", { runtime: "automatic" }]] |
| 129 | + }; |
| 130 | + } |
| 131 | +}; |
0 commit comments