Skip to content

Commit acd8904

Browse files
committed
update
1 parent c8f7dbc commit acd8904

File tree

8 files changed

+77
-52
lines changed

8 files changed

+77
-52
lines changed

index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ import getCommand from './utils/getCommand'
1818
import getLanguage from './utils/getLanguage'
1919
import renderEslint from './utils/renderEslint'
2020

21+
const util = require('util')
22+
const exec = util.promisify(require('child_process').exec)
23+
2124
function isValidPackageName(projectName) {
2225
return /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(projectName)
2326
}
@@ -566,6 +569,15 @@ async function init() {
566569
}
567570
console.log(` ${bold(green(getCommand(packageManager, 'dev')))}`)
568571
console.log()
572+
const cmds = [
573+
'pnpm i'
574+
/*'pnpm exec husky init',*/
575+
/*'pnpm run prepare'*/
576+
]
577+
for (const cmd of cmds) {
578+
const { stdout, stderr } = await exec(`cd ${root} && ${cmd}`)
579+
console.log(stdout, stderr)
580+
}
569581
}
570582

571583
init().catch((e) => {

pnpm-lock.yaml

Lines changed: 24 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

template/base/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
</head>
99
<body>
1010
<div id="app"></div>
11+
<script src="/config.js"></script>
1112
<script type="module" src="/src/main.js"></script>
1213
</body>
1314
</html>

template/base/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"dependencies": {
1111
"vue": "^3.4.15",
1212
"lodash": "^4.17.21",
13-
"axios": "^1.6.7"
13+
"axios": "^1.6.7",
14+
"query-string": "^8.2.0"
1415
},
1516
"devDependencies": {
1617
"@vitejs/plugin-vue": "^5.0.3",

template/base/src/api/apiIndex.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import Qs from 'querystring';
2-
import { HttpRequest } from '@/libs/custom_axios';
1+
import HttpRequest from '@/libs/custom_axios';
32
import config from '@/config/configIndex';
4-
import axios from 'axios';
3+
const mode = import.meta.env.MODE;
54

6-
let [backend_api] =
7-
process.env.NODE_ENV === 'development' ? [config.baseUrl.backend_dev] : [config.baseUrl.backend_pro];
5+
let [backend_api] = mode === 'development' ? [config.baseUrl.backend_dev] : [config.baseUrl.backend_pro];
86

97
export const axios_backend_api = new HttpRequest(backend_api);
108

119
let baseUrl = backend_api;
12-
if (baseUrl[baseUrl.length - 1] == '/') baseUrl = baseUrl.slice(0, -1);
10+
if (baseUrl[baseUrl.length - 1] === '/') baseUrl = baseUrl.slice(0, -1);
1311
export const prefixBackendBaseUrl = baseUrl;

template/base/src/config/configIndex.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
import queryString from 'query-string';
12
const BACKEND = import.meta.env.BACKEND;
23

3-
const Qs = require('querystring');
44
const public_config = window['CUSTOM_PUBLIC_CONFIG'];
5-
const url = window.___location.href + '';
6-
const paramsObj = Qs.decode(url.slice(url.indexOf('?') + 1));
5+
const paramsObj = queryString.parse(window.___location.search);
76

87
const local_config = {
98
baseUrl: {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import axios from 'axios';
2+
3+
class HttpRequest {
4+
baseUrl: string;
5+
queue: Record<string, any>;
6+
constructor(baseUrl = '') {
7+
this.baseUrl = baseUrl;
8+
this.queue = {};
9+
}
10+
getInsideConfig() {
11+
return {
12+
baseURL: this.baseUrl,
13+
headers: {
14+
//
15+
},
16+
};
17+
}
18+
destroy(url: string) {
19+
delete this.queue[url];
20+
/*if (!Object.keys(this.queue).length) {
21+
return;
22+
}*/
23+
}
24+
25+
request(options: Record<string, any>) {
26+
const instance = axios.create();
27+
options = Object.assign(this.getInsideConfig(), options);
28+
return instance(options);
29+
}
30+
}
31+
export default HttpRequest;

template/base/vite.config.js.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { defineConfig, loadEnv } from 'vite'
66
<%_ } _%>
77

88
// https://vitejs.dev/config/
9-
export default ({ mode }) => {
9+
export default ({ mode }: any) => {
1010
// import.meta.env.VITE_NAME available here with: process.env.VITE_NAME
1111
const env = loadEnv(mode, process.cwd());
1212
process.env = {...process.env, ...env};

0 commit comments

Comments
 (0)