2022-03-03 23:30:08 +08:00
|
|
|
|
import dayjs from "dayjs";
|
2021-10-16 16:16:58 +08:00
|
|
|
|
import { resolve } from "path";
|
2022-03-03 23:30:08 +08:00
|
|
|
|
import pkg from "./package.json";
|
2021-12-06 17:11:15 +08:00
|
|
|
|
import { warpperEnv, regExps } from "./build";
|
2022-02-05 14:45:20 +08:00
|
|
|
|
import { getPluginsList } from "./build/plugins";
|
2021-12-06 17:11:15 +08:00
|
|
|
|
import { UserConfigExport, ConfigEnv, loadEnv } from "vite";
|
2021-10-16 16:16:58 +08:00
|
|
|
|
|
2022-09-11 16:46:21 +08:00
|
|
|
|
/** 当前执行node命令时文件夹的地址(工作目录) */
|
2021-12-06 17:11:15 +08:00
|
|
|
|
const root: string = process.cwd();
|
|
|
|
|
|
2022-09-11 16:46:21 +08:00
|
|
|
|
/** 路径查找 */
|
2021-10-19 20:37:36 +08:00
|
|
|
|
const pathResolve = (dir: string): string => {
|
2021-10-16 16:16:58 +08:00
|
|
|
|
return resolve(__dirname, ".", dir);
|
|
|
|
|
};
|
|
|
|
|
|
2022-09-11 16:46:21 +08:00
|
|
|
|
/** 设置别名 */
|
2021-10-16 16:16:58 +08:00
|
|
|
|
const alias: Record<string, string> = {
|
2022-10-27 13:17:56 +08:00
|
|
|
|
"@": pathResolve("src"),
|
2022-03-14 14:49:02 +08:00
|
|
|
|
"@build": pathResolve("build")
|
2021-10-16 16:16:58 +08:00
|
|
|
|
};
|
|
|
|
|
|
2022-03-03 23:30:08 +08:00
|
|
|
|
const { dependencies, devDependencies, name, version } = pkg;
|
|
|
|
|
const __APP_INFO__ = {
|
|
|
|
|
pkg: { dependencies, devDependencies, name, version },
|
|
|
|
|
lastBuildTime: dayjs(new Date()).format("YYYY-MM-DD HH:mm:ss")
|
|
|
|
|
};
|
|
|
|
|
|
2021-10-16 16:16:58 +08:00
|
|
|
|
export default ({ command, mode }: ConfigEnv): UserConfigExport => {
|
2021-12-06 17:11:15 +08:00
|
|
|
|
const {
|
2022-10-26 19:51:06 +08:00
|
|
|
|
VITE_CDN,
|
2021-12-06 17:11:15 +08:00
|
|
|
|
VITE_PORT,
|
2021-12-17 15:09:02 +08:00
|
|
|
|
VITE_LEGACY,
|
2022-10-27 02:19:23 +08:00
|
|
|
|
VITE_COMPRESSION,
|
2021-12-06 17:11:15 +08:00
|
|
|
|
VITE_PUBLIC_PATH,
|
|
|
|
|
VITE_PROXY_DOMAIN,
|
|
|
|
|
VITE_PROXY_DOMAIN_REAL
|
|
|
|
|
} = warpperEnv(loadEnv(mode, root));
|
2021-10-16 16:16:58 +08:00
|
|
|
|
return {
|
2021-12-06 17:11:15 +08:00
|
|
|
|
base: VITE_PUBLIC_PATH,
|
2021-10-16 16:16:58 +08:00
|
|
|
|
root,
|
|
|
|
|
resolve: {
|
|
|
|
|
alias
|
|
|
|
|
},
|
|
|
|
|
// 服务端渲染
|
|
|
|
|
server: {
|
|
|
|
|
// 是否开启 https
|
|
|
|
|
https: false,
|
2021-12-06 17:11:15 +08:00
|
|
|
|
// 端口号
|
2021-10-16 16:16:58 +08:00
|
|
|
|
port: VITE_PORT,
|
|
|
|
|
host: "0.0.0.0",
|
|
|
|
|
// 本地跨域代理
|
2021-12-06 17:11:15 +08:00
|
|
|
|
proxy:
|
|
|
|
|
VITE_PROXY_DOMAIN_REAL.length > 0
|
|
|
|
|
? {
|
|
|
|
|
[VITE_PROXY_DOMAIN]: {
|
|
|
|
|
target: VITE_PROXY_DOMAIN_REAL,
|
|
|
|
|
// ws: true,
|
|
|
|
|
changeOrigin: true,
|
|
|
|
|
rewrite: (path: string) => regExps(path, VITE_PROXY_DOMAIN)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
: null
|
2021-10-16 16:16:58 +08:00
|
|
|
|
},
|
2022-10-27 02:19:23 +08:00
|
|
|
|
plugins: getPluginsList(command, VITE_LEGACY, VITE_CDN, VITE_COMPRESSION),
|
2021-10-16 16:16:58 +08:00
|
|
|
|
optimizeDeps: {
|
2022-10-28 15:32:31 +08:00
|
|
|
|
include: ["pinia", "lodash-es", "@vueuse/core", "dayjs"],
|
2022-03-17 15:45:11 +08:00
|
|
|
|
exclude: ["@pureadmin/theme/dist/browser-utils"]
|
2021-10-16 16:16:58 +08:00
|
|
|
|
},
|
|
|
|
|
build: {
|
|
|
|
|
sourcemap: false,
|
|
|
|
|
// 消除打包大小超过500kb警告
|
2022-10-27 15:51:06 +08:00
|
|
|
|
chunkSizeWarningLimit: 4000,
|
|
|
|
|
rollupOptions: {
|
|
|
|
|
input: {
|
|
|
|
|
index: pathResolve("index.html")
|
|
|
|
|
},
|
|
|
|
|
// 静态资源分类打包
|
|
|
|
|
output: {
|
|
|
|
|
chunkFileNames: "static/js/[name]-[hash].js",
|
|
|
|
|
entryFileNames: "static/js/[name]-[hash].js",
|
|
|
|
|
assetFileNames: "static/[ext]/[name]-[hash].[ext]"
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-10-16 16:16:58 +08:00
|
|
|
|
},
|
|
|
|
|
define: {
|
2022-03-03 23:30:08 +08:00
|
|
|
|
__INTLIFY_PROD_DEVTOOLS__: false,
|
|
|
|
|
__APP_INFO__: JSON.stringify(__APP_INFO__)
|
2021-10-16 16:16:58 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|