chore: separate configuration files
This commit is contained in:
parent
afbcf043fc
commit
e8aedefb38
8
.env
8
.env
|
|
@ -0,0 +1,8 @@
|
||||||
|
# port
|
||||||
|
VITE_PORT = 3100
|
||||||
|
|
||||||
|
# spa-title
|
||||||
|
VITE_GLOB_APP_TITLE = vben admin 2.0
|
||||||
|
|
||||||
|
# spa shortname
|
||||||
|
VITE_GLOB_APP_SHORT_NAME = vue_vben_admin_2x
|
||||||
|
|
@ -1 +1,14 @@
|
||||||
VITE_USE_MOCK=true
|
# Whether to open mock
|
||||||
|
VITE_USE_MOCK = true
|
||||||
|
|
||||||
|
# public path
|
||||||
|
VITE_PUBLIC_PATH = /
|
||||||
|
|
||||||
|
# Basic interface address SPA
|
||||||
|
VITE_GLOB_API_URL=/api
|
||||||
|
|
||||||
|
# Interface prefix
|
||||||
|
VITE_GLOB_API_URL_PREFIX=
|
||||||
|
|
||||||
|
# Cross-domain proxy, you can configure multiple
|
||||||
|
VITE_PROXY=[["/api","http://localhost:3000"]]
|
||||||
|
|
|
||||||
|
|
@ -1 +1,11 @@
|
||||||
VITE_USE_MOCK=true
|
# Whether to open mock
|
||||||
|
VITE_USE_MOCK = true
|
||||||
|
|
||||||
|
# public path
|
||||||
|
VITE_PUBLIC_PATH = ./
|
||||||
|
|
||||||
|
# Basic interface address SPA
|
||||||
|
VITE_GLOB_API_URL=/api
|
||||||
|
|
||||||
|
# Interface prefix
|
||||||
|
VITE_GLOB_API_URL_PREFIX=
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,16 @@
|
||||||
{
|
{
|
||||||
"recommendations": [
|
"recommendations": [
|
||||||
"octref.vetur",
|
"octref.vetur",
|
||||||
"dariofuzinato.vue-peek",
|
|
||||||
"dbaeumer.vscode-eslint",
|
"dbaeumer.vscode-eslint",
|
||||||
"stylelint.vscode-stylelint",
|
"stylelint.vscode-stylelint",
|
||||||
"DavidAnson.vscode-markdownlint",
|
"DavidAnson.vscode-markdownlint",
|
||||||
"esbenp.prettier-vscode",
|
"esbenp.prettier-vscode",
|
||||||
"mrmlnc.vscode-scss",
|
"mrmlnc.vscode-scss",
|
||||||
"Orta.vscode-jest"
|
"mrmlnc.vscode-less",
|
||||||
|
"cpylua.language-postcss",
|
||||||
|
"Orta.vscode-jest",
|
||||||
|
"antfu.iconify",
|
||||||
|
"mikestead.dotenv",
|
||||||
|
"bradlc.vscode-tailwindcss"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@ git clone https://github.com/anncwb/vue-vben-admin.git vue-vben-admin-2.0
|
||||||
|
|
||||||
cd vue-vben-admin-2.0
|
cd vue-vben-admin-2.0
|
||||||
|
|
||||||
// 如果使用别的包,可以执行安装
|
// 如果使用别的包管理工具,可以自行安装
|
||||||
// 如果未安装yarn,请运行:npm install -g yarn
|
// 如果未安装yarn,请运行:npm install -g yarn
|
||||||
yarn install
|
yarn install
|
||||||
|
|
||||||
|
|
@ -174,7 +174,7 @@ yarn clean:lib # 删除node_modules,兼容window系统
|
||||||
- `workflow` 工作流改进
|
- `workflow` 工作流改进
|
||||||
- `ci` 持续集成
|
- `ci` 持续集成
|
||||||
- `types` 类型定义文件更改
|
- `types` 类型定义文件更改
|
||||||
- `wip` 删除文件
|
- `wip` 开发中
|
||||||
|
|
||||||
## 代码贡献
|
## 代码贡献
|
||||||
|
|
||||||
|
|
@ -212,10 +212,8 @@ yarn clean:lib # 删除node_modules,兼容window系统
|
||||||
- [x] 二维码插件
|
- [x] 二维码插件
|
||||||
- [x] 国际化插件
|
- [x] 国际化插件
|
||||||
- [x] 详情组件
|
- [x] 详情组件
|
||||||
- [x] 图片裁剪
|
|
||||||
- [x] 验证码/验证组件
|
- [x] 验证码/验证组件
|
||||||
- [x] 树组件
|
- [x] 树组件
|
||||||
- [x] 系统性能优化
|
|
||||||
- [x] 兼容最新`vuex`,`vue-router`
|
- [x] 兼容最新`vuex`,`vue-router`
|
||||||
- [x] 图片预览组件
|
- [x] 图片预览组件
|
||||||
- [x] 表格组件
|
- [x] 表格组件
|
||||||
|
|
@ -234,6 +232,7 @@ yarn clean:lib # 删除node_modules,兼容window系统
|
||||||
- [ ] 黑暗主题
|
- [ ] 黑暗主题
|
||||||
- [ ] 打包 Gzip
|
- [ ] 打包 Gzip
|
||||||
- [ ] 抽取生产环境配置文件
|
- [ ] 抽取生产环境配置文件
|
||||||
|
- [ ] 系统性能优化
|
||||||
|
|
||||||
更多组件/功能/建议/bug/欢迎提交 pr 或者 issue
|
更多组件/功能/建议/bug/欢迎提交 pr 或者 issue
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import { networkInterfaces } from 'os';
|
import { networkInterfaces } from 'os';
|
||||||
import dotenv from 'dotenv';
|
import dotenv from 'dotenv';
|
||||||
|
|
||||||
export const isFunction = (arg: unknown): arg is (...args: any[]) => any =>
|
export const isFunction = (arg: unknown): arg is (...args: any[]) => any =>
|
||||||
typeof arg === 'function';
|
typeof arg === 'function';
|
||||||
export const isRegExp = (arg: unknown): arg is RegExp =>
|
export const isRegExp = (arg: unknown): arg is RegExp =>
|
||||||
|
|
@ -68,7 +67,14 @@ export function isReportMode(): boolean {
|
||||||
return process.env.REPORT === 'true';
|
return process.env.REPORT === 'true';
|
||||||
}
|
}
|
||||||
|
|
||||||
export function loadEnv() {
|
export interface ViteEnv {
|
||||||
|
VITE_PORT: number;
|
||||||
|
VITE_USE_MOCK: boolean;
|
||||||
|
VITE_PUBLIC_PATH: string;
|
||||||
|
VITE_PROXY: [string, string][];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function loadEnv(): ViteEnv {
|
||||||
const env = process.env.NODE_ENV;
|
const env = process.env.NODE_ENV;
|
||||||
const ret: any = {};
|
const ret: any = {};
|
||||||
const envList = [`.env.${env}.local`, `.env.${env}`, '.env.local', '.env', ,];
|
const envList = [`.env.${env}.local`, `.env.${env}`, '.env.local', '.env', ,];
|
||||||
|
|
@ -79,7 +85,16 @@ export function loadEnv() {
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const envName of Object.keys(process.env)) {
|
for (const envName of Object.keys(process.env)) {
|
||||||
const realName = (process.env as any)[envName].replace(/\\n/g, '\n');
|
let realName = (process.env as any)[envName].replace(/\\n/g, '\n');
|
||||||
|
realName = realName === 'true' ? true : realName === 'false' ? false : realName;
|
||||||
|
if (envName === 'VITE_PORT') {
|
||||||
|
realName = Number(realName);
|
||||||
|
}
|
||||||
|
if (envName === 'VITE_PROXY') {
|
||||||
|
try {
|
||||||
|
realName = JSON.parse(realName);
|
||||||
|
} catch (error) {}
|
||||||
|
}
|
||||||
ret[envName] = realName;
|
ret[envName] = realName;
|
||||||
process.env[envName] = realName;
|
process.env[envName] = realName;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
import type { GlobEnvConfig } from './src/types/config';
|
||||||
|
|
||||||
|
export const getGlobEnvConfig = (): GlobEnvConfig => {
|
||||||
|
const env = import.meta.env;
|
||||||
|
return (env as unknown) as GlobEnvConfig;
|
||||||
|
};
|
||||||
|
|
@ -82,7 +82,7 @@
|
||||||
"stylelint-config-prettier": "^8.0.2",
|
"stylelint-config-prettier": "^8.0.2",
|
||||||
"stylelint-config-standard": "^20.0.0",
|
"stylelint-config-standard": "^20.0.0",
|
||||||
"stylelint-order": "^4.1.0",
|
"stylelint-order": "^4.1.0",
|
||||||
"tailwindcss": "^1.8.10",
|
"tailwindcss": "^1.8.13",
|
||||||
"tasksfile": "^5.1.1",
|
"tasksfile": "^5.1.1",
|
||||||
"ts-node": "^9.0.0",
|
"ts-node": "^9.0.0",
|
||||||
"typescript": "^4.0.3",
|
"typescript": "^4.0.3",
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,21 @@ import type { ProjectConfig, GlobConfig, SettingWrap } from '/@/types/config';
|
||||||
|
|
||||||
import getProjectSetting from '/@/settings/projectSetting';
|
import getProjectSetting from '/@/settings/projectSetting';
|
||||||
|
|
||||||
|
import { getGlobEnvConfig } from '../../../getEnvConfig';
|
||||||
|
const {
|
||||||
|
VITE_GLOB_API_URL,
|
||||||
|
VITE_GLOB_APP_SHORT_NAME,
|
||||||
|
VITE_GLOB_APP_TITLE,
|
||||||
|
VITE_GLOB_API_URL_PREFIX,
|
||||||
|
} = getGlobEnvConfig();
|
||||||
|
|
||||||
export const useSetting = (): SettingWrap => {
|
export const useSetting = (): SettingWrap => {
|
||||||
// Take global configuration
|
// Take global configuration
|
||||||
const glob: Readonly<GlobConfig> = {
|
const glob: Readonly<GlobConfig> = {
|
||||||
title: 'vben admin 2.0',
|
title: VITE_GLOB_APP_TITLE,
|
||||||
apiUrl: '/api',
|
apiUrl: VITE_GLOB_API_URL,
|
||||||
shortName: 'vben_admin_v2',
|
shortName: VITE_GLOB_APP_SHORT_NAME,
|
||||||
urlPrefix: '',
|
urlPrefix: VITE_GLOB_API_URL_PREFIX,
|
||||||
};
|
};
|
||||||
const projectSetting: Readonly<ProjectConfig> = getProjectSetting;
|
const projectSetting: Readonly<ProjectConfig> = getProjectSetting;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -117,14 +117,14 @@ export interface GlobConfig {
|
||||||
}
|
}
|
||||||
export interface GlobEnvConfig {
|
export interface GlobEnvConfig {
|
||||||
// 网站标题
|
// 网站标题
|
||||||
GLOB_APP_TITLE: string;
|
VITE_GLOB_APP_TITLE: string;
|
||||||
|
|
||||||
// 项目路径
|
// 项目路径
|
||||||
GLOB_API_URL: string;
|
VITE_GLOB_API_URL: string;
|
||||||
|
|
||||||
GLOB_API_URL_PREFIX?: string;
|
VITE_GLOB_API_URL_PREFIX?: string;
|
||||||
|
|
||||||
GLOB_APP_SHORT_NAME: string;
|
VITE_GLOB_APP_SHORT_NAME: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改配置
|
// 修改配置
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { resolve } from 'path';
|
import { resolve } from 'path';
|
||||||
|
|
||||||
import type { UserConfig, Plugin as VitePlugin } from 'vite';
|
import type { UserConfig, Plugin as VitePlugin } from 'vite';
|
||||||
import type { Plugin } from 'rollup';
|
|
||||||
|
|
||||||
import visualizer from 'rollup-plugin-visualizer';
|
import visualizer from 'rollup-plugin-visualizer';
|
||||||
import { modifyVars } from './build/config/glob/lessModifyVars';
|
import { modifyVars } from './build/config/glob/lessModifyVars';
|
||||||
|
|
@ -12,12 +11,13 @@ import PurgeIcons from 'vite-plugin-purge-icons';
|
||||||
import { isDevFn, isReportMode, isProdFn, loadEnv } from './build/utils';
|
import { isDevFn, isReportMode, isProdFn, loadEnv } from './build/utils';
|
||||||
|
|
||||||
setupBasicEnv();
|
setupBasicEnv();
|
||||||
const { VITE_USE_MOCK } = loadEnv();
|
const { VITE_USE_MOCK, VITE_PORT, VITE_PUBLIC_PATH, VITE_PROXY } = loadEnv();
|
||||||
|
|
||||||
function pathResolve(dir: string) {
|
function pathResolve(dir: string) {
|
||||||
return resolve(__dirname, '.', dir);
|
return resolve(__dirname, '.', dir);
|
||||||
}
|
}
|
||||||
const rollupPlugins: Plugin[] = [];
|
|
||||||
|
const rollupPlugins: any[] = [];
|
||||||
const vitePlugins: VitePlugin[] = [];
|
const vitePlugins: VitePlugin[] = [];
|
||||||
|
|
||||||
(() => {
|
(() => {
|
||||||
|
|
@ -27,7 +27,7 @@ const vitePlugins: VitePlugin[] = [];
|
||||||
visualizer({ filename: './node_modules/.cache/stats.html', open: true }) as Plugin
|
visualizer({ filename: './node_modules/.cache/stats.html', open: true }) as Plugin
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (isDevFn() && VITE_USE_MOCK === 'true') {
|
if (isDevFn() && VITE_USE_MOCK) {
|
||||||
// open mock
|
// open mock
|
||||||
vitePlugins.push(
|
vitePlugins.push(
|
||||||
createMockServer({
|
createMockServer({
|
||||||
|
|
@ -39,17 +39,16 @@ const vitePlugins: VitePlugin[] = [];
|
||||||
})();
|
})();
|
||||||
|
|
||||||
const viteConfig: UserConfig = {
|
const viteConfig: UserConfig = {
|
||||||
silent: false,
|
/**
|
||||||
|
* 端口号
|
||||||
|
* @default '3000'
|
||||||
|
*/
|
||||||
|
port: VITE_PORT,
|
||||||
/**
|
/**
|
||||||
* 服务地址
|
* 服务地址
|
||||||
* @default 'localhost'
|
* @default 'localhost'
|
||||||
*/
|
*/
|
||||||
hostname: 'localhost',
|
hostname: 'localhost',
|
||||||
/**
|
|
||||||
* 端口号
|
|
||||||
* @default '3000'
|
|
||||||
*/
|
|
||||||
port: 3100,
|
|
||||||
/**
|
/**
|
||||||
* 运行自动打开浏览器·
|
* 运行自动打开浏览器·
|
||||||
* @default 'false'
|
* @default 'false'
|
||||||
|
|
@ -62,10 +61,10 @@ const viteConfig: UserConfig = {
|
||||||
*/
|
*/
|
||||||
minify: isDevFn() ? false : 'terser',
|
minify: isDevFn() ? false : 'terser',
|
||||||
/**
|
/**
|
||||||
* 在生产中投放时提供基本公共路径
|
* 基本公共路径
|
||||||
* @default '/'
|
* @default '/'
|
||||||
*/
|
*/
|
||||||
base: isDevFn() ? '/' : './',
|
base: VITE_PUBLIC_PATH,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 打包输入路径
|
* 打包输入路径
|
||||||
|
|
@ -91,7 +90,7 @@ const viteConfig: UserConfig = {
|
||||||
* @default 'es2019'
|
* @default 'es2019'
|
||||||
*/
|
*/
|
||||||
esbuildTarget: 'es2019',
|
esbuildTarget: 'es2019',
|
||||||
|
silent: false,
|
||||||
// 别名
|
// 别名
|
||||||
alias: {
|
alias: {
|
||||||
'/@/': pathResolve('src'),
|
'/@/': pathResolve('src'),
|
||||||
|
|
@ -112,7 +111,7 @@ const viteConfig: UserConfig = {
|
||||||
include: ['ant-design-vue/es/locale/zh_CN', '@ant-design/icons-vue', 'moment/locale/zh-cn'],
|
include: ['ant-design-vue/es/locale/zh_CN', '@ant-design/icons-vue', 'moment/locale/zh-cn'],
|
||||||
},
|
},
|
||||||
// 本地跨域代理
|
// 本地跨域代理
|
||||||
proxy: createProxy([['/api', 'http://localhost:3000']]),
|
proxy: createProxy(VITE_PROXY),
|
||||||
|
|
||||||
plugins: [PurgeIcons(), ...vitePlugins],
|
plugins: [PurgeIcons(), ...vitePlugins],
|
||||||
rollupOutputOptions: {},
|
rollupOutputOptions: {},
|
||||||
|
|
|
||||||
|
|
@ -6478,10 +6478,10 @@ table@^6.0.1:
|
||||||
slice-ansi "^4.0.0"
|
slice-ansi "^4.0.0"
|
||||||
string-width "^4.2.0"
|
string-width "^4.2.0"
|
||||||
|
|
||||||
tailwindcss@^1.8.10:
|
tailwindcss@^1.8.13:
|
||||||
version "1.8.10"
|
version "1.8.13"
|
||||||
resolved "https://registry.npm.taobao.org/tailwindcss/download/tailwindcss-1.8.10.tgz#945ef151c401c04a1c95e6a6bc747387a8d1b9dc"
|
resolved "https://registry.npmjs.org/tailwindcss/-/tailwindcss-1.8.13.tgz#ee57050a516d342bafc92cb74b4de6f92e44c189"
|
||||||
integrity sha1-lF7xUcQBwEocleamvHRzh6jRudw=
|
integrity sha512-z3R/6qPqfjauSR4qHhlA8I0OnfSyuotvigXISq666k+V52VSs5HV//KZ0Xe3qrZ4h5Um4OG5g+lcgjXSfURjDw==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@fullhuman/postcss-purgecss" "^2.1.2"
|
"@fullhuman/postcss-purgecss" "^2.1.2"
|
||||||
autoprefixer "^9.4.5"
|
autoprefixer "^9.4.5"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue