daofu-large-screen/vite.config.ts

103 lines
2.7 KiB
TypeScript
Raw Permalink Normal View History

2024-01-24 14:15:13 +08:00
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 => {
2024-01-29 14:05:14 +08:00
const { VITE_PORT, VITE_PUBLIC_PATH, VITE_PROXY, VITE_TITLE, VITE_BUILD_DROP_CONSOLE } = wrapperEnv(
2024-01-24 14:15:13 +08:00
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: {
2024-01-29 14:05:14 +08:00
minify: 'terser',
2024-01-24 14:15:13 +08:00
target: "es2020",
terserOptions: {
compress: {
2024-01-29 14:05:14 +08:00
drop_console: VITE_BUILD_DROP_CONSOLE, // 在生产环境移除console.log
2024-01-24 14:15:13 +08:00
drop_debugger: true // 在生产环境移除debugger
}
}
},
optimizeDeps: {
esbuildOptions: {
target: "es2020",
},
},
css: {
preprocessorOptions: {
scss: {
additionalData: `@import "./src/styles/variables";`,
},
},
},
};
};