Skip to content

Commit 62d075b

Browse files
still works, webpack 5 storybook
1 parent 451ab35 commit 62d075b

File tree

5 files changed

+13
-50
lines changed

5 files changed

+13
-50
lines changed

.storybook/main.js

+5-32
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,13 @@ module.exports = {
1212
},
1313
},
1414
'@storybook/addon-a11y',
15+
'storybook-addon-gatsby',
1516
],
16-
webpackFinal: async config => {
17-
// Transpile Gatsby module because Gatsby includes un-transpiled ES6 code.
18-
config.module.rules[0].exclude = [/node_modules\/(?!(gatsby)\/)/];
19-
// use installed babel-loader which is v8.0-beta (which is meant to work with @babel/core@7)
20-
config.module.rules[0].use[0].loader = require.resolve('babel-loader');
21-
// use @babel/preset-react for JSX and env (instead of staged presets)
22-
config.module.rules[0].use[0].options.presets = [
23-
require.resolve('@babel/preset-react'),
24-
require.resolve('@babel/preset-env'),
25-
];
26-
config.module.rules[0].use[0].options.plugins = [
27-
// use @babel/plugin-proposal-class-properties for class arrow functions
28-
require.resolve('@babel/plugin-proposal-class-properties'),
29-
// use babel-plugin-remove-graphql-queries to remove static queries from components when rendering in storybook
30-
require.resolve('babel-plugin-remove-graphql-queries'),
31-
];
32-
// Prefer Gatsby ES6 entrypoint (module) over commonjs (main) entrypoint
33-
config.resolve.mainFields = ['browser', 'module', 'main'];
34-
config.module.rules.push({
35-
test: /\.(ts|tsx)$/,
36-
loader: require.resolve('babel-loader'),
37-
options: {
38-
presets: [['react-app', { flow: false, typescript: true }]],
39-
plugins: [
40-
require.resolve('@babel/plugin-proposal-class-properties'),
41-
// use babel-plugin-remove-graphql-queries to remove static queries from components when rendering in storybook
42-
require.resolve('babel-plugin-remove-graphql-queries'),
43-
],
44-
},
45-
});
46-
config.resolve.extensions.push('.ts', '.tsx');
47-
return config;
17+
18+
core: {
19+
builder: 'webpack5',
4820
},
21+
4922
// https://github.com/storybookjs/storybook/issues/12585
5023
// react docgen typescript plugin hampers hot reloading time, so we'll disable it in development
5124
...(process.env.NODE_ENV === 'development'

.storybook/preview.js

+1-18
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import * as React from 'react';
2+
import { DarkModeContext } from '../src/context/DarkModeContext';
23
import '../src/styles/main.css';
34
import './storybook.css';
4-
import { DarkModeContext } from '../src/context/DarkModeContext';
5-
import { action } from '@storybook/addon-actions';
65

76
export const parameters = {
87
actions: { argTypesRegex: '^on[A-Z].*' },
@@ -48,19 +47,3 @@ export const decorators = [
4847
</div>
4948
),
5049
];
51-
52-
// Gatsby's Link overrides:
53-
// Gatsby Link calls the `enqueue` & `hovering` methods on the global variable ___loader.
54-
// This global object isn't set in storybook context, requiring you to override it to empty functions (no-op),
55-
// so Gatsby Link doesn't throw any errors.
56-
global.___loader = {
57-
enqueue: () => {},
58-
hovering: () => {},
59-
};
60-
// This global variable is prevents the "__BASE_PATH__ is not defined" error inside Storybook.
61-
global.__BASE_PATH__ = '/';
62-
// Navigating through a gatsby app using gatsby-link or any other gatsby component will use the `___navigate` method.
63-
// In Storybook it makes more sense to log an action than doing an actual navigate. Checkout the actions addon docs for more info: https://github.com/storybookjs/storybook/tree/master/addons/actions.
64-
window.___navigate = pathname => {
65-
action('NavigateTo:')(pathname);
66-
};

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
"remark-math": "4.0.0",
100100
"remark-mdx-frontmatter": "1.1.1",
101101
"remark-slug": "6.0.0",
102+
"storybook-addon-gatsby": "^0.0.5",
102103
"styled-components": "^5.3.5",
103104
"tailwindcss": "^3.1.3",
104105
"tippy.js": "^6.3.1",

src/components/markdown/CodeBlock/CodeBlock.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ class CodeBlock extends React.Component<
135135
> {
136136
codeSnips = [];
137137
static contextType = SpoilerContext;
138+
// declare context: React.ContextType<typeof SpoilerContext>;
138139
static defaultProps = {
139140
copyButton: true,
140141
};

yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -22077,6 +22077,11 @@ store2@^2.12.0:
2207722077
resolved "https://registry.npmjs.org/store2/-/store2-2.12.0.tgz"
2207822078
integrity sha512-7t+/wpKLanLzSnQPX8WAcuLCCeuSHoWdQuh9SB3xD0kNOM38DNf+0Oa+wmvxmYueRzkmh6IcdKFtvTa+ecgPDw==
2207922079

22080+
storybook-addon-gatsby@^0.0.5:
22081+
version "0.0.5"
22082+
resolved "https://registry.yarnpkg.com/storybook-addon-gatsby/-/storybook-addon-gatsby-0.0.5.tgz#94f5b67bab8659d0248b65e60dabc3702818ce8b"
22083+
integrity sha512-18f8Kc6mx8mEFfqY2DgF9ayDfmM58+9IjJqIxGV4bA4r2EtB/Q1LDNELIJmpLLyA5NrSvECxCqzLu7jNBlWgmA==
22084+
2208022085
storybook-dark-mode@^1.1.0:
2208122086
version "1.1.0"
2208222087
resolved "https://registry.yarnpkg.com/storybook-dark-mode/-/storybook-dark-mode-1.1.0.tgz#4aca307a9c09f1b95743da2db6b07c8eea99ed24"

0 commit comments

Comments
 (0)