Skip to content

Commit 8184bd9

Browse files
committed
storybook: test markdown support
1 parent a8dc23f commit 8184bd9

File tree

6 files changed

+1025
-35
lines changed

6 files changed

+1025
-35
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@
182182
"@eslint/compat": "^1.2.7",
183183
"@eslint/eslintrc": "^3.3.0",
184184
"@eslint/js": "^9.22.0",
185+
"@mdx-js/loader": "^3.1.0",
185186
"@pmmmwh/react-refresh-webpack-plugin": "0.5.16",
186187
"@sentry/jest-environment": "6.0.0",
187188
"@sentry/profiling-node": "9.16.1",
@@ -255,6 +256,7 @@
255256
"dev-ui-admin": "SENTRY_ADMIN_UI_DEV=1 yarn dev-ui",
256257
"dev-ui-admin-rspack": "SENTRY_ADMIN_UI_DEV=1 yarn dev-ui-rspack",
257258
"dev-ui-storybook": "STORYBOOK_TYPES=1 yarn dev-ui",
259+
"dev-ui-storybook-rspack": "STORYBOOK_TYPES=1 yarn dev-ui-rspack",
258260
"dev-acceptance": "NO_DEV_SERVER=1 NODE_ENV=development webpack --watch",
259261
"dev-acceptance-rspack": "NO_DEV_SERVER=1 NODE_ENV=development rspack --watch",
260262
"webpack-profile": "NO_TS_FORK=1 webpack --profile --json > stats.json",

rspack.config.ts

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {
77
DevServer,
88
OptimizationSplitChunksCacheGroup,
99
RspackPluginInstance,
10+
RuleSetRule,
1011
} from '@rspack/core';
1112
import rspack from '@rspack/core';
1213
import ReactRefreshRspackPlugin from '@rspack/plugin-react-refresh';
@@ -170,6 +171,35 @@ for (const locale of supportedLocales) {
170171
};
171172
}
172173

174+
const swcReactLoaderConfig: RuleSetRule['options'] = {
175+
jsc: {
176+
experimental: {
177+
plugins: [
178+
[
179+
'@swc/plugin-emotion',
180+
{
181+
sourceMap: true,
182+
// The "dev-only" option does not seem to apply correctly
183+
autoLabel: DEV_MODE ? 'always' : 'never',
184+
},
185+
],
186+
],
187+
},
188+
parser: {
189+
syntax: 'typescript',
190+
tsx: true,
191+
},
192+
transform: {
193+
react: {
194+
runtime: 'automatic',
195+
development: DEV_MODE,
196+
refresh: DEV_MODE,
197+
importSource: '@emotion/react',
198+
},
199+
},
200+
},
201+
};
202+
173203
/**
174204
* Main Webpack config for Sentry React SPA.
175205
*/
@@ -217,34 +247,19 @@ const appConfig: Configuration = {
217247
test: /\.(js|jsx|ts|tsx)$/,
218248
exclude: /\/node_modules\//,
219249
loader: 'builtin:swc-loader',
220-
options: {
221-
jsc: {
222-
experimental: {
223-
plugins: [
224-
[
225-
'@swc/plugin-emotion',
226-
{
227-
sourceMap: true,
228-
// The "dev-only" option does not seem to apply correctly
229-
autoLabel: DEV_MODE ? 'always' : 'never',
230-
},
231-
],
232-
],
233-
},
234-
parser: {
235-
syntax: 'typescript',
236-
tsx: true,
237-
},
238-
transform: {
239-
react: {
240-
runtime: 'automatic',
241-
development: DEV_MODE,
242-
refresh: DEV_MODE,
243-
importSource: '@emotion/react',
244-
},
245-
},
250+
options: swcReactLoaderConfig,
251+
},
252+
{
253+
test: /\.mdx?$/,
254+
use: [
255+
{
256+
loader: 'builtin:swc-loader',
257+
options: swcReactLoaderConfig,
246258
},
247-
},
259+
{
260+
loader: '@mdx-js/loader',
261+
},
262+
],
248263
},
249264
{
250265
test: /\.po$/,

static/app/components/core/colors.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import {Button} from 'sentry/components/core/button';
2+
3+
## Colors are rendering
4+
5+
<Button priority="primary">Test</Button>

static/app/views/stories/useStoriesLoader.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,33 @@ import {useMemo} from 'react';
44
import {useQuery, type UseQueryResult} from 'sentry/utils/queryClient';
55

66
const context = require.context('sentry', true, /\.stories.tsx$/, 'lazy');
7+
const mdxContext = require.context('sentry', true, /\.mdx$/, 'lazy');
78

89
export interface StoryDescriptor {
910
exports: Record<string, React.ComponentType | any>;
1011
filename: string;
1112
}
1213

1314
export function useStoryBookFiles() {
14-
return useMemo(() => context.keys().map(file => file.replace(/^\.\//, 'app/')), []);
15+
return useMemo(
16+
() =>
17+
[...context.keys(), ...mdxContext.keys()].map(file =>
18+
file.replace(/^\.\//, 'app/')
19+
),
20+
[]
21+
);
1522
}
1623

1724
async function importStory(filename: string): Promise<StoryDescriptor> {
18-
const story = await context(filename.replace(/^app\//, './'));
25+
if (filename.endsWith('.mdx')) {
26+
const story = await mdxContext(filename.replace(/^app\//, './'));
27+
return {
28+
exports: story,
29+
filename,
30+
};
31+
}
1932

33+
const story = await context(filename.replace(/^app\//, './'));
2034
return {
2135
exports: story,
2236
filename,

webpack.config.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,18 @@ const appConfig: webpack.Configuration = {
244244
{
245245
test: /\.[tj]sx?$/,
246246
include: [staticPrefix],
247-
exclude: /(vendor|node_modules|dist)/,
247+
exclude: [/(vendor|node_modules|dist)/],
248248
use: babelLoaderConfig,
249249
},
250+
{
251+
test: /\.mdx?$/,
252+
use: [
253+
babelLoaderConfig,
254+
{
255+
loader: '@mdx-js/loader',
256+
},
257+
],
258+
},
250259
{
251260
test: /\.po$/,
252261
use: {

0 commit comments

Comments
 (0)