Skip to content

Commit d8819c1

Browse files
committed
docs: 基础路径配置
1 parent af304df commit d8819c1

File tree

7 files changed

+87
-70
lines changed

7 files changed

+87
-70
lines changed

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

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace NodeJS {
2+
interface ProcessEnv {
3+
/**
4+
* @see https://nodejs.org/api/process.html#processenv
5+
*/
6+
NODE_ENV: 'development' | 'production' | 'test';
7+
8+
/**
9+
* vite 应用基础路径
10+
* Github deploy action
11+
*/
12+
VITE_APP_BASENAME?: string;
13+
}
14+
}

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

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
declare global {
2+
/**
3+
* package name
4+
* defined in vite.config.mts
5+
*/
6+
export const PKG_NAME: string;
7+
8+
/**
9+
* package version
10+
* defined in vite.config.mts
11+
*/
12+
export const PKG_VERSION: string;
13+
}
14+
15+
export {};

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

-21
This file was deleted.

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

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// <reference types="vite/client" />
2+
3+
interface ImportMetaEnv {
4+
// readonly VITE_APP_TITLE: string;
5+
}
6+
7+
interface ImportMeta {
8+
readonly env: ImportMetaEnv;
9+
}

Diff for: docs/src/main.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ import 'virtual:uno.css';
66
import 'virtual:svg-icons-register';
77
import App from './App';
88

9-
const basename = process.env.VITE_APP_BASENAME || '/';
10-
119
ReactDOM.createRoot(document.getElementById('root')!).render(
1210
<StrictMode>
13-
<HashRouter basename={basename}>
11+
<HashRouter basename={import.meta.env.BASE_URL}>
1412
<App />
1513
</HashRouter>
1614
</StrictMode>,

Diff for: docs/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"module": "ESNext",
77
"moduleResolution": "Node",
88
"resolveJsonModule": true,
9-
"types": ["vite/client"],
9+
"types": [],
1010
"allowImportingTsExtensions": true,
1111
"allowJs": true,
1212
"strict": true,

Diff for: docs/vite.config.mts

+47-45
Original file line numberDiff line numberDiff line change
@@ -11,52 +11,54 @@ import uno from 'unocss/vite';
1111
import { defineConfig } from 'vite';
1212
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
1313
import { ViteMinifyPlugin } from 'vite-plugin-minify';
14-
import { reactPages } from '../src';
14+
import { reactPages } from 'unplugin-react-pages';
1515
import pkg from './package.json';
1616

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

0 commit comments

Comments
 (0)