Skip to content

Commit

Permalink
feat: tup-700 storybook
Browse files Browse the repository at this point in the history
STEPS
1. `npm add -D @nx/storybook@17.2.8`
2. `npx nx@17.2.8 g @nx/storybook:configuration core-components --uiFramework="@storybook/react-vite" --bundler="vite"`
3. "Do you want to set up Storybook interaction tests? (Y/n) ›  false"

CONCERNS
1. Generator installed `@swc-node/register` and `@swc/core`.
2. `@vitejs/plugin-react-swc` is already isntalled.
3. [Storybook 7 does not work with @vitejs/plugin-react-swc](storybookjs/storybook#22381)
4. I worry I cannot move to Storybook 8 via NX, because it requires NX v18.
  • Loading branch information
wesleyboar committed Feb 26, 2024
1 parent ce1406b commit 41c6cfd
Show file tree
Hide file tree
Showing 9 changed files with 5,481 additions and 2,033 deletions.
20 changes: 20 additions & 0 deletions libs/core-components/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { StorybookConfig } from '@storybook/react-vite';

const config: StorybookConfig = {
stories: ['../src/lib/**/*.stories.@(js|jsx|ts|tsx|mdx)'],
addons: ['@storybook/addon-essentials'],
framework: {
name: '@storybook/react-vite',
options: {
builder: {
viteConfigPath: 'libs/core-components/vite.config.ts',
},
},
},
};

export default config;

// To customize your Vite configuration you can use the viteFinal field.
// Check https://storybook.js.org/docs/react/builders/vite#configuration
// and https://nx.dev/recipes/storybook/custom-builder-configs
Empty file.
25 changes: 25 additions & 0 deletions libs/core-components/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,31 @@
"passWithNoTests": true,
"reportsDirectory": "../../coverage/libs/core-components"
}
},
"storybook": {
"executor": "@nx/storybook:storybook",
"options": {
"port": 4400,
"configDir": "libs/core-components/.storybook"
},
"configurations": {
"ci": {
"quiet": true
}
}
},
"build-storybook": {
"executor": "@nx/storybook:build",
"outputs": ["{options.outputDir}"],
"options": {
"outputDir": "dist/storybook/core-components",
"configDir": "libs/core-components/.storybook"
},
"configurations": {
"ci": {
"quiet": true
}
}
}
}
}
3 changes: 3 additions & 0 deletions libs/core-components/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
},
{
"path": "./tsconfig.spec.json"
},
{
"path": "./tsconfig.storybook.json"
}
],
"extends": "../../tsconfig.base.json"
Expand Down
6 changes: 5 additions & 1 deletion libs/core-components/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
"**/*.spec.js",
"**/*.test.js",
"**/*.spec.jsx",
"**/*.test.jsx"
"**/*.test.jsx",
"**/*.stories.ts",
"**/*.stories.js",
"**/*.stories.jsx",
"**/*.stories.tsx"
],
"include": ["**/*.js", "**/*.jsx", "**/*.ts", "**/*.tsx"]
}
31 changes: 31 additions & 0 deletions libs/core-components/tsconfig.storybook.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"emitDecoratorMetadata": true,
"outDir": ""
},
"files": [
"../../node_modules/@nx/react/typings/styled-jsx.d.ts",
"../../node_modules/@nx/react/typings/cssmodule.d.ts",
"../../node_modules/@nx/react/typings/image.d.ts"
],
"exclude": [
"src/**/*.spec.ts",
"src/**/*.test.ts",
"src/**/*.spec.js",
"src/**/*.test.js",
"src/**/*.spec.tsx",
"src/**/*.test.tsx",
"src/**/*.spec.jsx",
"src/**/*.test.js"
],
"include": [
"src/**/*.stories.ts",
"src/**/*.stories.js",
"src/**/*.stories.jsx",
"src/**/*.stories.tsx",
"src/**/*.stories.mdx",
".storybook/*.js",
".storybook/*.ts"
]
}
21 changes: 20 additions & 1 deletion nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@
"@nx/vite:test": {
"inputs": ["default", "^production", "{workspaceRoot}/jest.preset.js"],
"cache": true
},
"build-storybook": {
"cache": true,
"inputs": [
"default",
"^production",
"{projectRoot}/.storybook/**/*",
"{projectRoot}/tsconfig.storybook.json"
]
}
},
"namedInputs": {
Expand All @@ -45,7 +54,17 @@
"!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)",
"!{projectRoot}/tsconfig.spec.json",
"!{projectRoot}/jest.config.[jt]s",
"!{projectRoot}/.eslintrc.json"
"!{projectRoot}/.eslintrc.json",
"!{projectRoot}/**/*.stories.@(js|jsx|ts|tsx|mdx)",
"!{projectRoot}/.storybook/**/*",
"!{projectRoot}/tsconfig.storybook.json"
]
},
"tasksRunnerOptions": {
"default": {
"options": {
"cacheableOperations": ["build-storybook"]
}
}
}
}
Loading

0 comments on commit 41c6cfd

Please sign in to comment.