forked from dnnsoftware/Dnn.Platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
93 lines (86 loc) · 3.03 KB
/
Copy pathmain.js
File metadata and controls
93 lines (86 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// This file has been automatically migrated to valid ESM format by Storybook.
import { join, dirname } from "path";
import { createRequire } from "module";
const require = createRequire(import.meta.url);
/**
* This function is used to resolve the absolute path of a package.
* It is needed in projects that use Yarn PnP or are set up within a monorepo.
*/
function getAbsolutePath(value) {
return dirname(require.resolve(join(value, "package.json")));
}
/** @type { import('@storybook/react-webpack5').StorybookConfig } */
const config = {
stories: [
"../src/**/*.mdx",
"../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"
],
addons: [
getAbsolutePath("@storybook/addon-webpack5-compiler-swc"),
getAbsolutePath("@storybook/addon-onboarding"),
getAbsolutePath("@storybook/addon-docs"),
],
framework: {
name: getAbsolutePath("@storybook/react-webpack5"),
options: {}
},
webpackFinal: async (config) => {
// Helper to check if a rule matches SVG files
const matchesSvg = (rule) => rule.test instanceof RegExp && rule.test.test('.svg');
// Exclude SVG from the default asset/resource rule (top-level and inside oneOf blocks)
config.module.rules.forEach((rule) => {
if (matchesSvg(rule)) {
rule.exclude = /\.svg$/i;
}
if (rule.oneOf) {
rule.oneOf.forEach((subRule) => {
if (matchesSvg(subRule)) {
subRule.exclude = /\.svg$/i;
}
});
}
});
// Add @svgr/webpack to handle SVG imports as React components
config.module.rules.push({
test: /\.svg$/i,
issuer: /\.[jt]sx?$/,
use: ["@svgr/webpack"],
});
config.module.rules.push({
test: /\.less$/,
use: [
require.resolve("style-loader"),
{
loader: require.resolve("css-loader"),
options: {
importLoaders: 1,
sourceMap: true,
modules: {
auto: true,
mode: "global",
localIdentName: "[name]__[local]___[hash:base64:5]",
},
esModule: false,
},
},
require.resolve("less-loader"),
],
});
// Ensure Storybook handles image imports the same way the runtime build does.
config.module.rules.push({
test: /\.(png|jpe?g|gif|webp|ico)$/i,
type: 'javascript/auto',
use: [
{
loader: require.resolve('file-loader'),
options: {
esModule: true,
name: 'static/media/[name].[hash].[ext]'
}
}
]
});
return config;
},
};
export default config;