Skip to content

Commit ce84f25

Browse files
committed
docs: 文档构建配置
1 parent d8819c1 commit ce84f25

File tree

5 files changed

+74
-65
lines changed

5 files changed

+74
-65
lines changed

Diff for: docs/src/dts/env.d.ts

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
1+
/**
2+
* env.d.ts
3+
* @ref https://nodejs.org/api/process.html#processenv
4+
*/
5+
16
namespace NodeJS {
27
interface ProcessEnv {
38
/**
49
* @see https://nodejs.org/api/process.html#processenv
510
*/
6-
NODE_ENV: 'development' | 'production' | 'test';
11+
readonly NODE_ENV: 'development' | 'production' | 'test';
12+
13+
/**
14+
* package name
15+
* defined in vite.config.mts
16+
*/
17+
readonly PKG_NAME: string;
718

819
/**
9-
* vite 应用基础路径
10-
* Github deploy action
20+
* package version
21+
* defined in vite.config.mts
1122
*/
12-
VITE_APP_BASENAME?: string;
23+
readonly PKG_VERSION: string;
1324
}
1425
}

Diff for: docs/src/dts/globals.d.ts

+5-11
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
declare global {
2-
/**
3-
* package name
4-
* defined in vite.config.mts
5-
*/
6-
export const PKG_NAME: string;
1+
/**
2+
* globals.d.ts
3+
*/
74

8-
/**
9-
* package version
10-
* defined in vite.config.mts
11-
*/
12-
export const PKG_VERSION: string;
5+
declare global {
6+
//
137
}
148

159
export {};

Diff for: docs/src/dts/vite.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* vite.d.ts
3+
* @ref https://vitejs.dev/guide/env-and-mode.html#intellisense-for-typescript
4+
*/
5+
16
/// <reference types="vite/client" />
27

38
interface ImportMetaEnv {

Diff for: docs/src/pages/(docs)/page.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ npm i -D unplugin-react-pages
99
```js
1010
import { defineConfig } from "vite";
1111
import react from "@vitejs/plugin-react";
12-
import reactApp from "unplugin-react-pages";
12+
import { reactPages } from "unplugin-react-pages";
1313

1414
export default defineConfig({
1515
plugins: [
1616
// plugins
1717
react(),
18-
reactApp(),
18+
reactPages.vite(),
1919
],
2020
});
2121
```

Diff for: docs/vite.config.mts

+47-48
Original file line numberDiff line numberDiff line change
@@ -8,57 +8,56 @@ import mdx from '@mdx-js/rollup';
88
import react from '@vitejs/plugin-react';
99
import rehypeHighlight from 'rehype-highlight';
1010
import uno from 'unocss/vite';
11-
import { defineConfig } from 'vite';
11+
import { defineConfig, loadEnv } from 'vite';
1212
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
1313
import { ViteMinifyPlugin } from 'vite-plugin-minify';
14-
import { reactPages } from 'unplugin-react-pages';
14+
// import { reactPages } from 'unplugin-react-pages';
15+
import { reactPages } from '../src';
1516
import pkg from './package.json';
1617

17-
export default defineConfig((config) => {
18-
return {
19-
base: process.env.VITE_APP_BASENAME || '/',
20-
server: {
21-
port: 15170,
22-
},
23-
define: {
24-
PKG_NAME: JSON.stringify(config.mode === 'test' ? 'pkg-name-for-test' : pkg.name),
25-
PKG_VERSION: JSON.stringify(config.mode === 'test' ? 'pkg-version-for-test' : pkg.version),
26-
},
27-
plugins: [
28-
// plugins
29-
react(),
30-
mdx({
31-
rehypePlugins: [
32-
//
33-
[
34-
rehypeHighlight,
35-
{
36-
detect: true,
37-
} as Parameters<typeof rehypeHighlight>[0],
38-
],
18+
export default defineConfig({
19+
base: process.env.VITE_APP_BASENAME || '/',
20+
server: {
21+
port: 15170,
22+
},
23+
define: {
24+
['process.env.PKG_NAME']: JSON.stringify(pkg.name),
25+
['process.env.PKG_VERSION']: JSON.stringify(pkg.version),
26+
},
27+
plugins: [
28+
// plugins
29+
react(),
30+
mdx({
31+
rehypePlugins: [
32+
//
33+
[
34+
rehypeHighlight,
35+
{
36+
detect: true,
37+
} as Parameters<typeof rehypeHighlight>[0],
3938
],
40-
}),
41-
uno(),
42-
createSvgIconsPlugin({
43-
iconDirs: [path.resolve('src/icons')],
44-
symbolId: 'icon-[dir]/[name]',
45-
}),
46-
ViteMinifyPlugin({
47-
minifyCSS: true,
48-
minifyJS: true,
49-
minifyURLs: true,
50-
removeComments: true,
51-
collapseWhitespace: true,
52-
removeScriptTypeAttributes: true,
53-
removeStyleLinkTypeAttributes: true,
54-
}),
55-
reactPages.vite({
56-
debug: true,
57-
logLevel: 'info',
58-
fileNames: {
59-
page: ['page.mdx', 'page.tsx'],
60-
},
61-
}),
62-
],
63-
};
39+
],
40+
}),
41+
uno(),
42+
createSvgIconsPlugin({
43+
iconDirs: [path.resolve('src/icons')],
44+
symbolId: 'icon-[dir]/[name]',
45+
}),
46+
ViteMinifyPlugin({
47+
minifyCSS: true,
48+
minifyJS: true,
49+
minifyURLs: true,
50+
removeComments: true,
51+
collapseWhitespace: true,
52+
removeScriptTypeAttributes: true,
53+
removeStyleLinkTypeAttributes: true,
54+
}),
55+
reactPages.vite({
56+
debug: true,
57+
logLevel: 'info',
58+
fileNames: {
59+
page: ['page.mdx', 'page.tsx'],
60+
},
61+
}),
62+
],
6463
});

0 commit comments

Comments
 (0)