Skip to content

Commit

Permalink
🏗️ refactor: 兼容文档构建方案
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Sep 3, 2023
1 parent 3060822 commit 2b6609e
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 33 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ build
.vercel
.dumi
.next
/public/docs
9 changes: 6 additions & 3 deletions .dumirc.ts → docs/.dumirc.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { defineConfig } from 'dumi';
import { Github } from 'lucide-react';

import { homepage } from './package.json';
import { homepage } from '../package.json';

const isProd = process.env.NODE_ENV === 'production';

const themeConfig = {
actions: [
Expand Down Expand Up @@ -30,10 +32,11 @@ export default defineConfig({
favicons: [
'https://registry.npmmirror.com/@lobehub/assets-emoji/1.3.0/files/assets/rainbow.webp',
],
// locales: [{ id: 'en-US', name: 'English' }],
mfsu: {},
base: isProd ? '/docs/' : '/',
publicPath: isProd ? '/docs/' : '/',
npmClient: 'pnpm',
outputPath: 'docs-dist',
outputPath: '../public/docs',
// ssr: isProduction ? {} : false,
styles: [
`html, body { background: transparent; }
Expand Down
2 changes: 1 addition & 1 deletion docs/changelog.md → docs/docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ nav:
order: 999
---

<embed src="../CHANGELOG.md"></embed>
<embed src="../../CHANGELOG.md"></embed>
File renamed without changes.
3 changes: 1 addition & 2 deletions docs/demo.tsx → docs/docs/demo.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Render from '@lobehub/chat-plugin-realtime-weather';

import Render from '../../src/Render';
import { data } from './data';

export default () => {
Expand Down
File renamed without changes.
14 changes: 14 additions & 0 deletions docs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "docs",
"version": "0.0.0",
"private": true,
"scripts": {
"build": "dumi build",
"dev": "PORT=8110 dumi dev"
},
"devDependencies": {
"babel-plugin-antd-style": "^1.0.4",
"dumi": "^2",
"dumi-theme-lobehub": "latest"
}
}
29 changes: 29 additions & 0 deletions docs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"compilerOptions": {
"module": "CommonJS",
"target": "ES5",
"lib": ["esnext", "DOM"],
"sourceMap": true,
"skipDefaultLibCheck": true,
"jsx": "react-jsx",
"baseUrl": ".",
"allowSyntheticDefaultImports": true,
"moduleResolution": "node",
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"paths": {
"@@/*": ["./dumi/tmp/*"],
"@/*": ["../src/*"]
},
"noEmit": true,
"incremental": true,
"esModuleInterop": true,
"isolatedModules": true
},
"exclude": ["node_modules"],
"include": [".", ".dumi/**/*", ".dumirc.ts", "../src"]
}
8 changes: 8 additions & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ const nextConfig = {
},
];
},
async rewrites() {
return [
{
source: '/docs',
destination: '/docs/index.html' // 你的 dumi 构建产物的 URL
},
]
},
};

export default nextConfig;
16 changes: 3 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,18 @@
"description": "Lobe Chat RealTime Weather Plugin",
"homepage": "https://github.com/lobehub/chat-plugin-realtime-weather",
"repository": "https://github.com/lobehub/chat-plugin-realtime-weather.git",
"main": "dist/index.js",
"files": [
"dist"
],
"scripts": {
"build": "next build",
"ci": "npm run lint && npm run type-check",
"dev": "next dev -p 3410",
"docs:build": "npm run build && dumi build",
"docs:dev": "PORT=8110 dumi dev",
"doctor": "father doctor",
"docs:build": "npm run build --prefix ./docs",
"docs:dev": "npm run dev --prefix ./docs",
"lint": "npm run lint:js && npm run lint:prettier",
"lint-staged:js": "eslint --ext .js,.jsx,.ts,.tsx ",
"lint:fix": "eslint --fix --cache --ext .js,.jsx,.ts,.tsx src/pages/api",
"lint:js": "eslint --cache --ext .js,.jsx,.ts,.tsx src/pages/api",
"lint:prettier": "prettier --check \\\"src/pages/api/**/*\\\" --end-of-line auto",
"prepare": "husky install",
"prepublishOnly": "npm run doctor && npm run build",
"prettier": "prettier -c --write \\\"src/pages/api/**/*\\\"",
"release": "semantic-release",
"start": "next start",
Expand Down Expand Up @@ -61,22 +55,18 @@
"devDependencies": {
"@lobehub/lint": "latest",
"@lobehub/ui": "latest",
"@types/react": "^18",
"@vercel/node": "^2",
"@vitest/coverage-v8": "latest",
"babel-plugin-antd-style": "^1.0.4",
"commitlint": "^17",
"cross-env": "^7",
"dumi": "^2",
"dumi-theme-lobehub": "latest",
"eslint": "^8",
"father": "^4.3.1",
"husky": "^8",
"lint-staged": "^13",
"lucide-react": "latest",
"prettier": "^3",
"semantic-release": "^21",
"typescript": "^5",
"vercel": "^28",
"vitest": "latest"
}
}
3 changes: 3 additions & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
packages:
- 'docs'
- .
2 changes: 1 addition & 1 deletion public/manifest-dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"identifier": "realtime-weather-dev",
"ui": {
"mode": "iframe",
"url": "http://localhost:3410",
"url": "http://localhost:3410/iframe",
"height": 310
},
"version": "1"
Expand Down
15 changes: 15 additions & 0 deletions src/pages/iframe.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { fetchPluginMessage } from '@lobehub/chat-plugin-sdk';
import { Skeleton } from 'antd';
import { memo } from 'react';
import useSWR from 'swr';

import Render from '@/Render';
import { WeatherResult } from '@/type';

const Home = memo(() => {
const { isLoading, data } = useSWR<WeatherResult>('fetchDataFromChat', fetchPluginMessage);

return isLoading || !data ? <Skeleton active /> : <Render content={data} name={'test'} />;
});

export default Home;
21 changes: 9 additions & 12 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { fetchPluginMessage } from '@lobehub/chat-plugin-sdk';
import { Skeleton } from 'antd';
import { memo } from 'react';
import useSWR from 'swr';
import { useRouter } from 'next/router';
import { useEffect } from 'react';

import Render from '@/Render';
import { WeatherResult } from '@/type';
export default () => {
const router = useRouter();

const Home = memo(() => {
const { isLoading, data } = useSWR<WeatherResult>('fetchDataFromChat', fetchPluginMessage);
useEffect(() => {
router.replace('/docs');
}, []);

return isLoading || !data ? <Skeleton active /> : <Render content={data} name={'test'} />;
});

export default Home;
return null;
};
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"skipDefaultLibCheck": true,
"jsx": "preserve",
"baseUrl": ".",
"types": ["node"],
"allowSyntheticDefaultImports": true,
"moduleResolution": "node",
"forceConsistentCasingInFileNames": true,
Expand Down

0 comments on commit 2b6609e

Please sign in to comment.