Skip to content

Commit 312e678

Browse files
committed
feat(storybook): vite + chore(pnpm): hoist storybook
`storiesOf` are deprecated with `storyStoreV7` so `Icon.stories.tsx` is being explicitly ignored in storybook until it's been refactored
1 parent fba7001 commit 312e678

File tree

9 files changed

+2791
-694
lines changed

9 files changed

+2791
-694
lines changed

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
public-hoist-pattern[]=*storybook*

.storybook/main.js

+42-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,44 @@
1-
//'../packages/**/*.stories.mdx',
1+
const { sync: glob } = require('fast-glob');
2+
const tsconfigPaths = require('vite-tsconfig-paths');
3+
4+
// do not change
5+
const previewFolder = 'node_modules/.cache/storybook/public';
6+
7+
// create `cache` folder if not exists
8+
require('fs').mkdirSync(previewFolder, { recursive: true });
9+
10+
/** @type {import('@storybook/builder-vite').StorybookViteConfig} */
211
module.exports = {
3-
stories: [
4-
"../packages/**/*.stories.mdx",
5-
"../packages/**/*.stories.@(js|jsx|ts|tsx)",
6-
],
7-
addons: [
8-
"@storybook/addon-links",
9-
"@storybook/addon-essentials",
10-
"@storybook/addon-interactions",
11-
],
12-
framework: "@storybook/react",
12+
stories: glob('packages/**/*.stories.@(js|jsx|ts|tsx)', {
13+
ignore: [
14+
'packages/**/node_modules/**/*',
15+
'packages/**/Icon.stories.tsx',
16+
],
17+
onlyFiles: true,
18+
absolute: true,
19+
}),
20+
addons: ['@storybook/addon-links', '@storybook/addon-essentials'],
21+
framework: '@storybook/react',
22+
staticDirs: ['../' + previewFolder],
23+
typescript: {
24+
check: true,
25+
},
26+
core: {
27+
builder: '@storybook/builder-vite',
28+
disableTelemetry: true,
29+
},
30+
features: {
31+
storyStoreV7: true,
32+
},
33+
async viteFinal(config, { configType }) {
34+
config.plugins.push(tsconfigPaths.default());
35+
config.resolve = {
36+
...config.resolve,
37+
alias: {
38+
...config.resolve.alias,
39+
fs: require.resolve('rollup-plugin-node-builtins'),
40+
},
41+
};
42+
return config;
43+
},
1344
};

.storybook/preview.js

+13-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
export const parameters = {
2-
actions: { argTypesRegex: '^on[A-Z].*' },
3-
controls: {
4-
matchers: {
5-
color: /(background|color)$/i,
6-
date: /Date$/
7-
}
8-
},
9-
options: {
10-
storySort: (a, b) => (a[1].kind === b[1].kind ? 0 : a[1].id.localeCompare(b[1].id, undefined, { numeric: true }))
11-
}
2+
actions: { argTypesRegex: '^on[A-Z].*' },
3+
controls: {
4+
matchers: {
5+
color: /(background|color)$/i,
6+
date: /Date$/,
7+
},
8+
},
9+
options: {
10+
storySort: (a, b) =>
11+
a.title === b.title
12+
? 0
13+
: a.id.localeCompare(b.id, undefined, { numeric: true }),
14+
},
1215
};

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,15 @@
4949
"@vitejs/plugin-react": "^1.3.2",
5050
"eslint": "~8.12.0",
5151
"eslint-config-prettier": "8.1.0",
52+
"fast-glob": "^3.2.11",
5253
"jest": "^28.1.0",
5354
"jest-styled-components": "^7.0.8",
5455
"react": "^18.0.0",
5556
"react-dom": "^18.0.0",
5657
"react-lazily": "^0.9.1",
5758
"rollup-plugin-dts": "^4.2.1",
59+
"rollup-plugin-node-builtins": "^2.1.2",
60+
"storybook": "^6.5.8",
5861
"styled-components": "^5.3.5",
5962
"ts-jest": "27.1.4",
6063
"ts-node": "9.1.1",

packages/config/vite.config.ts

+22-21
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
import react from '@vitejs/plugin-react';
2+
import { PluginOption } from 'vite';
23
import { UserConfigExport } from 'vite';
34
import dts from 'vite-plugin-dts';
45

56
/**
6-
*
77
* @param cwd
8-
* @param external
8+
* @param external packages as peer dependencies
99
*/
1010
const config = (cwd: string, external?: string[]): UserConfigExport => {
11-
return {
12-
root: cwd,
13-
plugins: [
14-
react(),
15-
dts({ entryRoot: cwd + "/src", outputDir: cwd + "/dist" }),
16-
],
17-
build: {
18-
emptyOutDir: true,
19-
lib: {
20-
entry: cwd + '/src/index.ts',
21-
fileName: 'index',
22-
formats: ['es', 'cjs'],
23-
},
24-
outDir: cwd + '/dist',
25-
rollupOptions: {
26-
external,
27-
},
28-
},
29-
};
11+
const cfg: UserConfigExport = {
12+
root: cwd,
13+
plugins: [
14+
react() as PluginOption,
15+
dts({ entryRoot: cwd + '/src', outputDir: cwd + '/dist' }),
16+
],
17+
build: {
18+
emptyOutDir: true,
19+
lib: {
20+
entry: cwd + '/src/index.ts',
21+
fileName: 'index',
22+
formats: ['es', 'cjs'],
23+
},
24+
outDir: cwd + '/dist',
25+
rollupOptions: {
26+
external,
27+
},
28+
},
29+
};
30+
return cfg;
3031
};
3132
export default config;

packages/core/vite.config.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { defineConfig } from 'vite';
1+
import { defineConfig, UserConfigExport } from 'vite';
22
import config from './node_modules/@web3uikit/config/vite.config';
33

4-
export default defineConfig({ ...config(__dirname, ['react', 'react-dom']) });
4+
export default defineConfig({
5+
...(config(__dirname, ['react', 'react-dom']) as UserConfigExport),
6+
});

packages/icons/vite.config.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { defineConfig } from 'vite';
1+
import { defineConfig, UserConfigExport } from 'vite';
22
import config from './node_modules/@web3uikit/config/vite.config';
33

4-
export default defineConfig({ ...config(__dirname, ['react', 'react-dom']) });
4+
export default defineConfig({
5+
...(config(__dirname, ['react', 'react-dom']) as UserConfigExport),
6+
});

packages/ui/vite.config.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { defineConfig } from 'vite';
1+
import { defineConfig, UserConfigExport } from 'vite';
22
import config from './node_modules/@web3uikit/config/vite.config';
33

44
export default defineConfig({
5-
...config(__dirname, ['react', 'react-dom', 'moralis', 'react-moralis']),
5+
...(config(__dirname, ['react', 'react-dom']) as UserConfigExport),
66
});

0 commit comments

Comments
 (0)