diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml
index 98bb027..5f21659 100644
--- a/.gitea/workflows/ci.yaml
+++ b/.gitea/workflows/ci.yaml
@@ -152,7 +152,7 @@ jobs:
- uses: actions/setup-node@v4
with: { node-version: 20, cache: npm }
- run: npm ci
- - run: npm run build-storybook
+ - run: npm run storybook:build:github
- run: npm run test:sb
env: { CI: true }
@@ -174,4 +174,4 @@ jobs:
with: { node-version: 20, cache: npm }
- run: npm ci
- run: npm run build
- - run: npm run build-storybook
+ - run: npm run storybook:build:github
diff --git a/.storybook/main.github.js b/.storybook/main.github.js
deleted file mode 100644
index 7afbb5d..0000000
--- a/.storybook/main.github.js
+++ /dev/null
@@ -1,35 +0,0 @@
-/** @type { import('@storybook/nextjs-vite').StorybookConfig } */
-const config = {
- stories: [
- "../stories/**/*.mdx",
- "../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)",
- ],
- addons: [
- "@chromatic-com/storybook",
- "@storybook/addon-docs",
- "@storybook/addon-onboarding",
- "@storybook/addon-a11y",
- "@storybook/addon-vitest",
- ],
- framework: {
- name: "@storybook/nextjs-vite",
- options: {},
- },
- staticDirs: ["../public"],
- managerHead: (head) => `${head}`,
- previewHead: (head) => `${head}`,
- async viteFinal(cfg) {
- // IMPORTANT: Set base path for GitHub Pages sub-path hosting
- cfg.base = "/communityrulestorybook/";
- // Ensure esbuild treats .js as JSX during dep pre-bundling
- cfg.optimizeDeps ??= {};
- cfg.optimizeDeps.esbuildOptions ??= {};
- cfg.optimizeDeps.esbuildOptions.loader = {
- ...(cfg.optimizeDeps.esbuildOptions.loader || {}),
- ".js": "jsx",
- ".ts": "tsx",
- };
- return cfg;
- },
-};
-export default config;
diff --git a/.storybook/main.js b/.storybook/main.js
index 777757c..57cad99 100644
--- a/.storybook/main.js
+++ b/.storybook/main.js
@@ -17,7 +17,30 @@ const config = {
options: {},
},
staticDirs: ["../public"],
+
+ // Auto-detect environment and apply appropriate settings
+ managerHead: (head) => {
+ // Only add base href for GitHub Pages (when CI=true or specific environment)
+ if (process.env.CI || process.env.STORYBOOK_BASE_PATH) {
+ return `${head}`;
+ }
+ return head;
+ },
+
+ previewHead: (head) => {
+ // Only add base href for GitHub Pages
+ if (process.env.CI || process.env.STORYBOOK_BASE_PATH) {
+ return `${head}`;
+ }
+ return head;
+ },
+
async viteFinal(cfg) {
+ // Set base path for GitHub Pages when needed
+ if (process.env.CI || process.env.STORYBOOK_BASE_PATH) {
+ cfg.base = "/communityrulestorybook/";
+ }
+
// Ensure esbuild treats .js as JSX during dep pre-bundling
cfg.optimizeDeps ??= {};
cfg.optimizeDeps.esbuildOptions ??= {};
@@ -29,4 +52,5 @@ const config = {
return cfg;
},
};
+
export default config;
diff --git a/.storybook/main.local.js b/.storybook/main.local.js
deleted file mode 100644
index 6e3993d..0000000
--- a/.storybook/main.local.js
+++ /dev/null
@@ -1,31 +0,0 @@
-/** @type { import('@storybook/nextjs-vite').StorybookConfig } */
-const config = {
- stories: [
- "../stories/**/*.mdx",
- "../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)",
- ],
- addons: [
- "@chromatic-com/storybook",
- "@storybook/addon-docs",
- "@storybook/addon-onboarding",
- "@storybook/addon-a11y",
- "@storybook/addon-vitest",
- ],
- framework: {
- name: "@storybook/nextjs-vite",
- options: {},
- },
- staticDirs: ["../public"],
- async viteFinal(cfg) {
- // Ensure esbuild treats .js as JSX during dep pre-bundling
- cfg.optimizeDeps ??= {};
- cfg.optimizeDeps.esbuildOptions ??= {};
- cfg.optimizeDeps.esbuildOptions.loader = {
- ...(cfg.optimizeDeps.esbuildOptions.loader || {}),
- ".js": "jsx",
- ".ts": "tsx",
- };
- return cfg;
- },
-};
-export default config;
diff --git a/.storybook/preview.github.js b/.storybook/preview.github.js
deleted file mode 100644
index 8b6689a..0000000
--- a/.storybook/preview.github.js
+++ /dev/null
@@ -1,49 +0,0 @@
-import "../app/globals.css";
-
-// Import Google Fonts for Storybook
-import { Inter, Bricolage_Grotesque, Space_Grotesk } from "next/font/google";
-
-const inter = Inter({
- subsets: ["latin"],
- weight: ["400", "500", "600", "700"],
- variable: "--font-inter",
- display: "swap",
-});
-
-const bricolageGrotesque = Bricolage_Grotesque({
- subsets: ["latin"],
- weight: ["400", "500", "700", "800"],
- variable: "--font-bricolage-grotesque",
- display: "swap",
-});
-
-const spaceGrotesk = Space_Grotesk({
- subsets: ["latin"],
- weight: ["400", "500", "700"],
- variable: "--font-space-grotesk",
- display: "swap",
-});
-
-/** @type { import('@storybook/react').Preview } */
-const preview = {
- parameters: {
- actions: { argTypesRegex: "^on[A-Z].*" },
- controls: {
- matchers: {
- color: /(background|color)$/i,
- date: /Date$/i,
- },
- },
- },
- decorators: [
- (Story) => (
-
-
-
- ),
- ],
-};
-
-export default preview;
diff --git a/.storybook/preview.js b/.storybook/preview.js
index f48bdf5..8b6689a 100644
--- a/.storybook/preview.js
+++ b/.storybook/preview.js
@@ -34,9 +34,6 @@ const preview = {
date: /Date$/i,
},
},
- a11y: { element: '#storybook-root', manual: false },
- viewport: { defaultViewport: 'responsive' },
- chromatic: { viewports: [360, 768, 1024, 1440] } // breakpoints
},
decorators: [
(Story) => (
diff --git a/.storybook/preview.local.js b/.storybook/preview.local.js
deleted file mode 100644
index 8b6689a..0000000
--- a/.storybook/preview.local.js
+++ /dev/null
@@ -1,49 +0,0 @@
-import "../app/globals.css";
-
-// Import Google Fonts for Storybook
-import { Inter, Bricolage_Grotesque, Space_Grotesk } from "next/font/google";
-
-const inter = Inter({
- subsets: ["latin"],
- weight: ["400", "500", "600", "700"],
- variable: "--font-inter",
- display: "swap",
-});
-
-const bricolageGrotesque = Bricolage_Grotesque({
- subsets: ["latin"],
- weight: ["400", "500", "700", "800"],
- variable: "--font-bricolage-grotesque",
- display: "swap",
-});
-
-const spaceGrotesk = Space_Grotesk({
- subsets: ["latin"],
- weight: ["400", "500", "700"],
- variable: "--font-space-grotesk",
- display: "swap",
-});
-
-/** @type { import('@storybook/react').Preview } */
-const preview = {
- parameters: {
- actions: { argTypesRegex: "^on[A-Z].*" },
- controls: {
- matchers: {
- color: /(background|color)$/i,
- date: /Date$/i,
- },
- },
- },
- decorators: [
- (Story) => (
-
-
-
- ),
- ],
-};
-
-export default preview;
diff --git a/README.md b/README.md
index fb0a00e..9af8c81 100644
--- a/README.md
+++ b/README.md
@@ -52,59 +52,46 @@ npm run test:sb
## 📚 Storybook Development
-This project includes Storybook for component development and documentation. The setup supports both local development and GitHub Pages deployment.
+This project includes Storybook for component development and documentation. The setup automatically detects the environment and applies the appropriate configuration.
### Local Development
-For local Storybook development (no base path):
+For local Storybook development:
```bash
npm run storybook:local
+# or simply
+npm run storybook
```
This will:
-- Copy local configuration files (without GitHub Pages base path)
- Start Storybook at `http://localhost:6006`
-- Ignore configuration changes in git
+- Use relative paths for assets (no base path)
-### Production Deployment
+### GitHub Pages Deployment
-When ready to deploy to GitHub Pages:
+For GitHub Pages deployment with base path:
-1. **Restore GitHub Pages configuration:**
+```bash
+npm run storybook:build:github
+```
- ```bash
- npm run storybook:restore
- ```
+This will:
-2. **Build Storybook:**
+- Build Storybook with `/communityrulestorybook/` base path
+- Generate files ready for GitHub Pages deployment
- ```bash
- npm run build-storybook
- ```
+### CI/CD Integration
-3. **Deploy to GitHub Pages repository:**
+The CI pipeline automatically uses the GitHub Pages configuration when building Storybook.
- ```bash
- # Copy the build to your GitHub Pages repository
- cp -r storybook-static/* /path/to/communityrulestorybook/
+### Configuration
- # Or if you have it as a git submodule:
- cp -r storybook-static/* communityrulestorybook/
- cd communityrulestorybook
- git add .
- git commit -m "Update Storybook build"
- git push origin main
- ```
+The Storybook configuration automatically detects the environment:
-### Switching Between Configurations
-
-- **Local Development:** `npm run storybook:local`
-- **Production Build:** `npm run storybook:restore` then `npm run build-storybook`
-- **Back to Local:** `npm run storybook:local`
-
-The gitignore is configured to prevent configuration file changes from triggering git changes during local development.
+- **Local development**: No base path, relative assets
+- **CI/Production**: Base path `/communityrulestorybook/` for GitHub Pages
## 📋 Available Scripts
@@ -127,9 +114,10 @@ The gitignore is configured to prevent configuration file changes from triggerin
### Storybook
-- `npm run storybook:local` - Start Storybook with local configuration
-- `npm run storybook:restore` - Restore GitHub Pages configuration
-- `npm run build-storybook` - Build Storybook for production
+- `npm run storybook:local` - Start Storybook for local development
+- `npm run storybook:github` - Start Storybook with GitHub Pages configuration
+- `npm run storybook:build` - Build Storybook for local deployment
+- `npm run storybook:build:github` - Build Storybook for GitHub Pages
- `npm run storybook` - Start Storybook with current configuration
## 🏗️ Project Structure
diff --git a/package.json b/package.json
index 7b334fc..6c898c9 100644
--- a/package.json
+++ b/package.json
@@ -9,8 +9,10 @@
"lint": "next lint",
"postinstall": "npm rebuild lightningcss",
"storybook": "storybook dev -p 6006",
- "storybook:local": "cp .storybook/main.local.js .storybook/main.js && cp .storybook/preview.local.js .storybook/preview.js && storybook dev -p 6006",
- "storybook:restore": "cp .storybook/main.github.js .storybook/main.js && cp .storybook/preview.github.js .storybook/preview.js",
+ "storybook:local": "storybook dev -p 6006",
+ "storybook:github": "STORYBOOK_BASE_PATH=true storybook dev -p 6006",
+ "storybook:build": "storybook build",
+ "storybook:build:github": "STORYBOOK_BASE_PATH=true storybook build",
"build-storybook": "storybook build",
"test": "vitest run --coverage",
"test:watch": "vitest",