Skip to content

Commit ea181bf

Browse files
uyarnxuczdependabot[bot]richerfu
authored
fix: site path and use history router (Tencent#136)
* feat: 代码优化 (Tencent#22) * feat: 代码优化 * fix: fix card title * fix: fix color * fix: 修复饼图文字重叠 (Tencent#57) * chore(deps): bump axios from 0.21.4 to 0.26.1 (Tencent#54) Bumps [axios](https://github.com/axios/axios) from 0.21.4 to 0.26.1. - [Release notes](https://github.com/axios/axios/releases) - [Changelog](https://github.com/axios/axios/blob/master/CHANGELOG.md) - [Commits](axios/axios@v0.21.4...v0.26.1) --- updated-dependencies: - dependency-name: axios dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix: 修复图表文字重叠, fixes Tencent#50 * fix: loss css token (Tencent#58) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: yuyang <uyarnchen@gmail.com> * feat: add maintenance page (Tencent#73) * fix(typo): fix form menu title typo (Tencent#74) * chore(deps): bump qrcode.react from 3.0.1 to 3.0.2 Bumps [qrcode.react](https://github.com/zpao/qrcode.react) from 3.0.1 to 3.0.2. - [Release notes](https://github.com/zpao/qrcode.react/releases) - [Changelog](https://github.com/zpao/qrcode.react/blob/main/CHANGELOG.md) - [Commits](zpao/qrcode.react@v3.0.1...v3.0.2) --- updated-dependencies: - dependency-name: qrcode.react dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * fix(datepicker): refactor date-picker (Tencent#87) * fix: site path and use history router Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: 巅峰召唤师cz <xuczgh@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: 巅峰召唤师cz <xuchaozheng@outlook.com> Co-authored-by: southorange1228 <32590310+southorange1228@users.noreply.github.com>
1 parent 4bf2eae commit ea181bf

File tree

9 files changed

+81
-61
lines changed

9 files changed

+81
-61
lines changed

.env

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
VITE_SOME_KEY=123
2+
# 打包路径 根据项目不同按需配置
3+
VITE_BASE_URL = ./

.env.development

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
VITE_SOME_KEY=456
2+
# 打包路径
3+
VITE_BASE_URL = ./

.env.site

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
VITE_SOME_KEY=123
2+
# 打包路径 根据项目不同按需配置
3+
VITE_BASE_URL = https://static.tdesign.tencent.com/starter/react/

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"dev": "vite --open --mode development",
88
"dev:linux": "vite --mode development",
99
"build:test": "vite build --mode test",
10-
"build": "vite build --mode production",
10+
"build": "vite build --mode release",
11+
"build:site": "vite build --mode site",
1112
"site:preview": "npm run build && cp -r dist _site",
1213
"preview": "vite preview --mode test",
1314
"test": "echo \"no test specified,work in process\"",

src/configs/host.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ export default {
1111
// 测试环境接口地址
1212
API: 'https://service-exndqyuk-1257786608.gz.apigw.tencentcs.com',
1313
},
14-
production: {
14+
release: {
1515
// 正式环境接口地址
1616
API: 'https://service-bv448zsw-1257786608.gz.apigw.tencentcs.com',
1717
},
18+
site: {
19+
// TDesign部署特殊需要 与release功能一致
20+
API: 'https://service-bv448zsw-1257786608.gz.apigw.tencentcs.com',
21+
},
1822
};

src/global.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ declare module 'tvision-color';
4848

4949
declare interface ImportMeta {
5050
env: {
51-
MODE: 'development' | 'test' | 'production';
51+
MODE: 'development' | 'test' | 'release' | 'mock' | 'site';
5252
};
5353
}

src/main.tsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
33
import { Provider } from 'react-redux';
4-
import { HashRouter } from 'react-router-dom';
4+
import { BrowserRouter } from 'react-router-dom';
55
import store from 'modules/store';
66
import App from 'layouts/index';
77

88
import 'tdesign-react/es/style/index.css';
9+
910
import './styles/theme.less';
1011
import './styles/index.less';
1112

13+
const env = import.meta.env.MODE || 'development';
14+
const baseRouterName = env === 'site' ? '/starter/react/' : '';
15+
1216
const renderApp = () => {
1317
ReactDOM.render(
1418
<Provider store={store}>
15-
<HashRouter>
19+
<BrowserRouter basename={baseRouterName}>
1620
<App />
17-
</HashRouter>
21+
</BrowserRouter>
1822
</Provider>,
1923
document.getElementById('app'),
2024
);

tsconfig.json

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
{
22
"compilerOptions": {
33
"baseUrl": "src",
4-
"target": "es5",
5-
"lib": [
6-
"dom",
7-
"dom.iterable",
8-
"esnext"
9-
],
4+
"target": "esnext",
5+
"lib": ["dom", "dom.iterable", "esnext"],
106
"allowJs": true,
117
"skipLibCheck": true,
128
"esModuleInterop": true,
@@ -21,7 +17,5 @@
2117
"noEmit": true,
2218
"jsx": "react-jsx"
2319
},
24-
"include": [
25-
"src"
26-
]
20+
"include": ["src"]
2721
}

vite.config.js

+54-46
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,69 @@
11
import path from 'path';
2+
import { loadEnv } from 'vite';
23
import { viteMockServe } from 'vite-plugin-mock';
34
import react from '@vitejs/plugin-react';
45
import svgr from '@honkhonk/vite-plugin-svgr';
56

6-
export default (params) => ({
7-
base: './',
8-
resolve: {
9-
alias: {
10-
assets: path.resolve(__dirname, './src/assets'),
11-
components: path.resolve(__dirname, './src/components'),
12-
configs: path.resolve(__dirname, './src/configs'),
13-
layouts: path.resolve(__dirname, './src/layouts'),
14-
modules: path.resolve(__dirname, './src/modules'),
15-
pages: path.resolve(__dirname, './src/pages'),
16-
styles: path.resolve(__dirname, './src/styles'),
17-
utils: path.resolve(__dirname, './src/utils'),
18-
services: path.resolve(__dirname, './src/services'),
19-
router: path.resolve(__dirname, './src/router'),
20-
hooks: path.resolve(__dirname, './src/hooks'),
21-
types: path.resolve(__dirname, './src/types'),
7+
const CWD = process.cwd();
8+
9+
export default (params) => {
10+
const { mode } = params;
11+
const { VITE_BASE_URL } = loadEnv(mode, CWD);
12+
13+
return {
14+
base: VITE_BASE_URL,
15+
resolve: {
16+
alias: {
17+
assets: path.resolve(__dirname, './src/assets'),
18+
components: path.resolve(__dirname, './src/components'),
19+
configs: path.resolve(__dirname, './src/configs'),
20+
layouts: path.resolve(__dirname, './src/layouts'),
21+
modules: path.resolve(__dirname, './src/modules'),
22+
pages: path.resolve(__dirname, './src/pages'),
23+
styles: path.resolve(__dirname, './src/styles'),
24+
utils: path.resolve(__dirname, './src/utils'),
25+
services: path.resolve(__dirname, './src/services'),
26+
router: path.resolve(__dirname, './src/router'),
27+
hooks: path.resolve(__dirname, './src/hooks'),
28+
types: path.resolve(__dirname, './src/types'),
29+
},
2230
},
23-
},
2431

25-
css: {
26-
preprocessorOptions: {
27-
less: {
28-
modifyVars: {
29-
// 如需自定义组件其他 token, 在此处配置
32+
css: {
33+
preprocessorOptions: {
34+
less: {
35+
modifyVars: {
36+
// 如需自定义组件其他 token, 在此处配置
37+
},
3038
},
3139
},
3240
},
33-
},
3441

35-
plugins: [
36-
svgr(),
37-
react(),
38-
params.mode === 'mock' &&
39-
viteMockServe({
40-
mockPath: './mock',
41-
localEnabled: true,
42-
}),
43-
],
42+
plugins: [
43+
svgr(),
44+
react(),
45+
mode === 'mock' &&
46+
viteMockServe({
47+
mockPath: './mock',
48+
localEnabled: true,
49+
}),
50+
],
4451

45-
build: {
46-
cssCodeSplit: false,
47-
},
52+
build: {
53+
cssCodeSplit: false,
54+
},
4855

49-
server: {
50-
host: '0.0.0.0',
51-
port: 3003,
52-
proxy: {
53-
'/api': {
54-
// 用于开发环境下的转发请求
55-
// 更多请参考:https://vitejs.dev/config/#server-proxy
56-
target: 'https://service-exndqyuk-1257786608.gz.apigw.tencentcs.com',
57-
changeOrigin: true,
56+
server: {
57+
host: '0.0.0.0',
58+
port: 3003,
59+
proxy: {
60+
'/api': {
61+
// 用于开发环境下的转发请求
62+
// 更多请参考:https://vitejs.dev/config/#server-proxy
63+
target: 'https://service-exndqyuk-1257786608.gz.apigw.tencentcs.com',
64+
changeOrigin: true,
65+
},
5866
},
5967
},
60-
},
61-
});
68+
};
69+
};

0 commit comments

Comments
 (0)