103 lines
2.7 KiB
TypeScript
103 lines
2.7 KiB
TypeScript
import { UserConfigExport, ConfigEnv, loadEnv } from "vite";
|
|
import { resolve } from "path";
|
|
import { wrapperEnv } from "./build/utils";
|
|
import { createProxy } from "./build/proxy";
|
|
import vue from "@vitejs/plugin-vue";
|
|
import vueJsx from "@vitejs/plugin-vue-jsx";
|
|
import html from "vite-plugin-html";
|
|
import viteSvgLoader from "vite-plugin-svg-icons";
|
|
import { vitePluginMars3d } from 'vite-plugin-mars3d'
|
|
|
|
const pathResolve = (dir: string): string => {
|
|
return resolve(__dirname, ".", dir);
|
|
};
|
|
|
|
const alias: Record<string, string> = {
|
|
"@": pathResolve("src"),
|
|
"@build": pathResolve("build"),
|
|
//解决开发环境下的警告 You are running the esm-bundler build of vue-i18n. It is recommended to configure your bundler to explicitly replace feature flag globals with boolean literals to get proper tree-shaking in the final bundle.
|
|
"vue-i18n": "vue-i18n/dist/vue-i18n.cjs.js",
|
|
};
|
|
|
|
const root: string = process.cwd();
|
|
|
|
// https://vitejs.dev/config/
|
|
export default ({ command, mode }: ConfigEnv): UserConfigExport => {
|
|
const { VITE_PORT, VITE_PUBLIC_PATH, VITE_PROXY, VITE_TITLE, VITE_BUILD_DROP_CONSOLE } = wrapperEnv(
|
|
loadEnv(mode, root)
|
|
);
|
|
// 获取 .env 文件里定义的环境变量
|
|
const ENV = loadEnv(mode, root)
|
|
|
|
return {
|
|
/**
|
|
* 基本公共路径
|
|
* /manages/ 可根据项目部署域名的后缀自行填写(全局搜/manages/替换)
|
|
* @default '/'
|
|
*/
|
|
base: process.env.NODE_ENV === "production" ? "./" : VITE_PUBLIC_PATH,
|
|
root,
|
|
resolve: {
|
|
alias,
|
|
},
|
|
// 服务端渲染
|
|
server: {
|
|
// 是否开启 https
|
|
https: false,
|
|
/**
|
|
* 端口号
|
|
* @default 3000
|
|
*/
|
|
port: VITE_PORT,
|
|
host: "0.0.0.0",
|
|
// 本地跨域代理
|
|
proxy: createProxy(VITE_PROXY),
|
|
},
|
|
plugins: [
|
|
vue(),
|
|
vueJsx(),
|
|
vitePluginMars3d(),
|
|
html({
|
|
inject: {
|
|
injectData: {
|
|
VITE_TITLE,
|
|
},
|
|
},
|
|
minify: true,
|
|
}),
|
|
viteSvgLoader({
|
|
iconDirs: [pathResolve("./src/assets/svg")],
|
|
symbolId: "icon-[dir]-[name]",
|
|
}),
|
|
],
|
|
define: {
|
|
"process.env": {
|
|
BASE_URL: ENV.VITE_PUBLIC_PATH,
|
|
},
|
|
buildTime: new Date()
|
|
},
|
|
build: {
|
|
minify: 'terser',
|
|
target: "es2020",
|
|
terserOptions: {
|
|
compress: {
|
|
drop_console: VITE_BUILD_DROP_CONSOLE, // 在生产环境移除console.log
|
|
drop_debugger: true // 在生产环境移除debugger
|
|
}
|
|
}
|
|
},
|
|
optimizeDeps: {
|
|
esbuildOptions: {
|
|
target: "es2020",
|
|
},
|
|
},
|
|
css: {
|
|
preprocessorOptions: {
|
|
scss: {
|
|
additionalData: `@import "./src/styles/variables";`,
|
|
},
|
|
},
|
|
},
|
|
};
|
|
};
|