加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
vite.config.js 2.03 KB
一键复制 编辑 原始数据 按行查看 历史
yongkang 提交于 2024-06-25 19:08 . config
import { resolve } from "path";
import { defineConfig, loadEnv } from "vite";
import { setupVitePlugins, viteDefine } from "./build";
/** 路径查找 */
const pathResolve = (dir) => {
return resolve(__dirname, ".", dir);
};
export default defineConfig(({ mode }) => {
const viteEnv = loadEnv(mode, process.cwd());
return {
base: viteEnv.VITE_BASE_URL,
define: viteDefine,
resolve: {
/** 设置别名 */
alias: {
"@": pathResolve("src"),
"~": pathResolve("./"),
}
},
server: {
// 端口号
port: viteEnv.VITE_PORT,
open: true,
host: "0.0.0.0",
// 本地跨域代理 https://cn.vitejs.dev/config/server-options.html#server-proxy
proxy: {},
},
plugins: setupVitePlugins(viteEnv),
css: {
preprocessorOptions: {
scss: {
additionalData: `@use "./src/styles/mixin.scss" as *;`,
},
},
},
// https://cn.vitejs.dev/config/dep-optimization-options.html#dep-optimization-options
optimizeDeps: {
// include,
// exclude,
},
build: {
// https://cn.vitejs.dev/guide/build.html#browser-compatibility
// target: "es2015",
// 生成生产源映射
sourcemap: viteEnv.VITE_SOURCE_MAP === "Y",
// 消除打包大小超过500kb警告
chunkSizeWarningLimit: 4000,
rollupOptions: {
input: {
index: pathResolve("index.html"),
},
// 静态资源分类打包
output: {
chunkFileNames: "static/js/[name]-[hash].js",
entryFileNames: "static/js/[name]-[hash].js",
// #https://cn.rollupjs.org/configuration-options/#output-assetfilenames
assetFileNames: "static/[ext]/[name]-[hash].[ext]",
// 手动分包 #https://cn.rollupjs.org/configuration-options/#output-manualchunks
manualChunks(id) {
if (id.includes('node_modules')) return 'vendor';
},
},
},
// 启用/ 禁用 gzip 压缩大小报告
reportCompressedSize: false,
},
};
});
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化