@sys-designer/create-vue 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -0
- package/cli.mjs +133 -0
- package/package.json +26 -0
- package/template/.env.development +13 -0
- package/template/.env.electron +13 -0
- package/template/.env.production +11 -0
- package/template/.eslintrc-auto-import.json +96 -0
- package/template/README.md +2 -0
- package/template/_gitignore +32 -0
- package/template/build/proxy.ts +34 -0
- package/template/build/utils.ts +71 -0
- package/template/common/routes.ts +7 -0
- package/template/index.css +10 -0
- package/template/index.html +23 -0
- package/template/package.json +51 -0
- package/template/public/favicon.ico +0 -0
- package/template/src/App.vue +18 -0
- package/template/src/assets/styles/reset.scss +0 -0
- package/template/src/assets/styles/vars.scss +0 -0
- package/template/src/env.d.ts +5 -0
- package/template/src/main.ts +13 -0
- package/template/src/router/index.ts +44 -0
- package/template/src/store/global.ts +60 -0
- package/template/src/store/index.ts +9 -0
- package/template/src/store/user.ts +61 -0
- package/template/src/types/auto-imports.d.ts +93 -0
- package/template/src/types/components.d.ts +22 -0
- package/template/src/utils/crypto.ts +160 -0
- package/template/src/utils/dsl.ts +101 -0
- package/template/src/utils/index.ts +30 -0
- package/template/src/utils/is.ts +122 -0
- package/template/src/utils/request.ts +51 -0
- package/template/src/views/index.vue +23 -0
- package/template/src/vite-env.d.ts +31 -0
- package/template/tsconfig.json +37 -0
- package/template/tsconfig.node.json +20 -0
- package/template/vite.config.ts +99 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { useGlobal, useUser } from '@/store';
|
|
2
|
+
import axios, { AxiosError, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
|
|
3
|
+
import { createDiscreteApi } from 'naive-ui'
|
|
4
|
+
const { message } = createDiscreteApi(['message']);
|
|
5
|
+
|
|
6
|
+
const service = axios.create({
|
|
7
|
+
baseURL: import.meta.env.VITE_APP_BASE_URL,
|
|
8
|
+
timeout: 10000
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
// 请求拦截器
|
|
12
|
+
service.interceptors.request.use(
|
|
13
|
+
(config: InternalAxiosRequestConfig) => {
|
|
14
|
+
const token = useUser().getToken()
|
|
15
|
+
if (token) {
|
|
16
|
+
config.headers['Authorization'] = ('Bearer ' + token) as any;
|
|
17
|
+
}
|
|
18
|
+
const global = useGlobal();
|
|
19
|
+
const projectId = global.getProjectId()
|
|
20
|
+
if(projectId){
|
|
21
|
+
config.headers['x-project-id'] = projectId
|
|
22
|
+
}
|
|
23
|
+
return config
|
|
24
|
+
},
|
|
25
|
+
err => Promise.reject(err)
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
// 响应拦截器
|
|
29
|
+
service.interceptors.response.use(
|
|
30
|
+
(res: AxiosResponse<any>) => {
|
|
31
|
+
return res
|
|
32
|
+
},
|
|
33
|
+
err => {
|
|
34
|
+
const data = err.response?.data;
|
|
35
|
+
// const code = data?.code;
|
|
36
|
+
const msg = data?.message;
|
|
37
|
+
if(msg){
|
|
38
|
+
message.error(msg)
|
|
39
|
+
}
|
|
40
|
+
return Promise.reject(err)
|
|
41
|
+
}
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
export default service
|
|
45
|
+
|
|
46
|
+
export const request = {
|
|
47
|
+
service: service,
|
|
48
|
+
onErrorResponse: (error: AxiosError, _resolve: any, reject: any)=>{
|
|
49
|
+
reject(error)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<n-space vertical>
|
|
3
|
+
<n-button type="primary" @click="showMsg">弹出消息</n-button>
|
|
4
|
+
<n-input v-model:value="inputVal"/>
|
|
5
|
+
<n-select v-model:value="selectVal" :options="options" placeholder="下拉选择" />
|
|
6
|
+
</n-space>
|
|
7
|
+
</template>
|
|
8
|
+
|
|
9
|
+
<script setup lang="ts">
|
|
10
|
+
|
|
11
|
+
const inputVal = ref('')
|
|
12
|
+
const selectVal = ref('')
|
|
13
|
+
const options = [
|
|
14
|
+
{ label: '选项1', value: '1' },
|
|
15
|
+
{ label: '选项2', value: '2' }
|
|
16
|
+
]
|
|
17
|
+
const message = useMessage();
|
|
18
|
+
|
|
19
|
+
const showMsg = () => {
|
|
20
|
+
message.success('NaiveUI + Vue3 + TS + Vite 搭建成功!')
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
</script>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// src/env.d.ts
|
|
2
|
+
/// <reference types="vite/client" />
|
|
3
|
+
declare const __IS_ELECTRON__: boolean;
|
|
4
|
+
import type {
|
|
5
|
+
MessageApi,
|
|
6
|
+
DialogApi,
|
|
7
|
+
NotificationApi,
|
|
8
|
+
LoadingBarApi
|
|
9
|
+
} from 'naive-ui'
|
|
10
|
+
|
|
11
|
+
declare global {
|
|
12
|
+
interface Window {
|
|
13
|
+
$message: MessageApi
|
|
14
|
+
$dialog: DialogApi
|
|
15
|
+
$notification: NotificationApi
|
|
16
|
+
$loadingBar: LoadingBarApi
|
|
17
|
+
electronAPI: {
|
|
18
|
+
sendLoginSuccess: (loginInfo?: Record<string, any>) => void
|
|
19
|
+
setGlobal: (info?: Record<string, any>) => void
|
|
20
|
+
closeWindow: () => void
|
|
21
|
+
minimizeWindow: () => void
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
declare module '*.vue' {
|
|
27
|
+
import type { DefineComponent } from 'vue'
|
|
28
|
+
const component: DefineComponent<{}, {}, any>
|
|
29
|
+
export default component
|
|
30
|
+
}
|
|
31
|
+
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"useDefineForClassFields": true,
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
|
|
9
|
+
/* 路径别名 */
|
|
10
|
+
"moduleResolution": "bundler",
|
|
11
|
+
"resolveJsonModule": true,
|
|
12
|
+
"isolatedModules": true,
|
|
13
|
+
"noEmit": true,
|
|
14
|
+
"jsx": "preserve",
|
|
15
|
+
|
|
16
|
+
/* 类型检查 */
|
|
17
|
+
"strict": true,
|
|
18
|
+
"noUnusedLocals": true,
|
|
19
|
+
"noUnusedParameters": true,
|
|
20
|
+
"noFallthroughCasesInSwitch": true,
|
|
21
|
+
"paths": {
|
|
22
|
+
"@/*": ["./src/*"],
|
|
23
|
+
"@common/*": ["./common/*"]
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"include": [
|
|
27
|
+
"src/**/*.ts",
|
|
28
|
+
"src/**/*.tsx",
|
|
29
|
+
"src/**/*.vue",
|
|
30
|
+
"src/auto-imports.d.ts",
|
|
31
|
+
"src/components.d.ts",
|
|
32
|
+
"src/types/*.d.ts",
|
|
33
|
+
"common/*.vue",
|
|
34
|
+
"common/*.ts",
|
|
35
|
+
],
|
|
36
|
+
"references": [{ "path": "./tsconfig.node.json" }]
|
|
37
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"composite": true,
|
|
4
|
+
"target": "ES2022",
|
|
5
|
+
"lib": ["ES2022"],
|
|
6
|
+
"module": "ESNext",
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
|
|
9
|
+
"moduleResolution": "bundler",
|
|
10
|
+
"allowImportingTsExtensions": true,
|
|
11
|
+
"resolveJsonModule": true,
|
|
12
|
+
"isolatedModules": true,
|
|
13
|
+
|
|
14
|
+
"strict": true,
|
|
15
|
+
"noUnusedLocals": true,
|
|
16
|
+
"noUnusedParameters": true,
|
|
17
|
+
"noFallthroughCasesInSwitch": true
|
|
18
|
+
},
|
|
19
|
+
"include": ["vite.config.ts"]
|
|
20
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { defineConfig, loadEnv } from 'vite';
|
|
2
|
+
import vue from '@vitejs/plugin-vue';
|
|
3
|
+
import { wrapperEnv } from './build/utils';
|
|
4
|
+
import { createProxy } from './build/proxy';
|
|
5
|
+
import AutoImport from 'unplugin-auto-import/vite';
|
|
6
|
+
import Components from 'unplugin-vue-components/vite';
|
|
7
|
+
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers';
|
|
8
|
+
import { resolve } from 'path';
|
|
9
|
+
import { createHtmlPlugin } from 'vite-plugin-html';
|
|
10
|
+
import { viteMockServe } from 'vite-plugin-mock';
|
|
11
|
+
import viteCompression from 'vite-plugin-compression';
|
|
12
|
+
import { libResolves, libModules } from './common/lib.config';
|
|
13
|
+
|
|
14
|
+
const pathResolve = (dir: string) => resolve(__dirname, dir);
|
|
15
|
+
|
|
16
|
+
export default defineConfig(({ command, mode }) => {
|
|
17
|
+
const env = loadEnv(mode, process.cwd(), '');
|
|
18
|
+
const isDev = command === 'serve';
|
|
19
|
+
const viteEnv = wrapperEnv(env);
|
|
20
|
+
const { VITE_PUBLIC_PATH, VITE_PORT, VITE_PROXY } = viteEnv;
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
base: VITE_PUBLIC_PATH,
|
|
24
|
+
plugins: [
|
|
25
|
+
vue(),
|
|
26
|
+
AutoImport({
|
|
27
|
+
imports: [
|
|
28
|
+
'vue',
|
|
29
|
+
'vue-router',
|
|
30
|
+
'pinia',
|
|
31
|
+
{ 'naive-ui': ['useDialog', 'useMessage', 'useNotification', 'useLoadingBar', 'useModal'] }
|
|
32
|
+
],
|
|
33
|
+
dts: 'src/types/auto-imports.d.ts',
|
|
34
|
+
eslintrc: { enabled: true }
|
|
35
|
+
}),
|
|
36
|
+
Components({
|
|
37
|
+
resolvers: [NaiveUiResolver()],
|
|
38
|
+
dts: 'src/types/components.d.ts',
|
|
39
|
+
}),
|
|
40
|
+
createHtmlPlugin({ inject: { data: { title: env.VITE_APP_TITLE } } }),
|
|
41
|
+
viteMockServe({ mockPath: 'mock', localEnabled: isDev, prodEnabled: false, watchFiles: true }),
|
|
42
|
+
viteCompression({
|
|
43
|
+
algorithm: 'gzip',
|
|
44
|
+
threshold: 10240,
|
|
45
|
+
deleteOriginFile: false,
|
|
46
|
+
filter: /\.(js|css|json|html|svg|ttf)$/i
|
|
47
|
+
})
|
|
48
|
+
],
|
|
49
|
+
resolve: {
|
|
50
|
+
alias: {
|
|
51
|
+
'@': pathResolve('src'),
|
|
52
|
+
'@common': pathResolve('common'),
|
|
53
|
+
...libResolves,
|
|
54
|
+
'@common-impl': pathResolve('src'),
|
|
55
|
+
},
|
|
56
|
+
dedupe: ['vue', 'naive-ui', 'vue-router', 'pinia']
|
|
57
|
+
},
|
|
58
|
+
optimizeDeps: {
|
|
59
|
+
include: [
|
|
60
|
+
...libModules.filter(it=> it.custom).map(it => it.name),
|
|
61
|
+
'naive-ui'
|
|
62
|
+
]
|
|
63
|
+
},
|
|
64
|
+
css: {
|
|
65
|
+
preprocessorOptions: {
|
|
66
|
+
scss: { additionalData: `@use "@/assets/styles/vars.scss";` }
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
server: {
|
|
70
|
+
host: true,
|
|
71
|
+
port: VITE_PORT,
|
|
72
|
+
proxy: createProxy(VITE_PROXY),
|
|
73
|
+
strictPort: false,
|
|
74
|
+
},
|
|
75
|
+
build: {
|
|
76
|
+
outDir: 'dist',
|
|
77
|
+
chunkSizeWarningLimit: 1500,
|
|
78
|
+
rollupOptions: {
|
|
79
|
+
output: {
|
|
80
|
+
manualChunks: {
|
|
81
|
+
vue: ['vue', 'vue-router'],
|
|
82
|
+
naive: ['naive-ui'],
|
|
83
|
+
vendor: ['pinia', 'axios', 'dayjs', 'lodash']
|
|
84
|
+
},
|
|
85
|
+
entryFileNames: 'js/[name]-[hash].js',
|
|
86
|
+
chunkFileNames: 'js/[name]-[hash].js',
|
|
87
|
+
assetFileNames: (info) => {
|
|
88
|
+
const ext = info.name.split('.').pop()
|
|
89
|
+
if (/css/.test(ext)) return 'css/[name]-[hash].css'
|
|
90
|
+
if (/png|jpe?g|svg|gif/.test(ext)) return 'img/[name]-[hash].[ext]'
|
|
91
|
+
return 'assets/[name]-[hash].[ext]'
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
minify: 'terser',
|
|
96
|
+
terserOptions: { compress: { drop_console: !isDev } }
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
});
|