2 Star 0 Fork 640

牟皓明/epp-admin-uniapp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
vite.config.ts 3.29 KB
一键复制 编辑 原始数据 按行查看 历史
mou-haoming 提交于 2025-01-06 15:11 . feat: 资产申领
import { defineConfig, loadEnv } from "vite";
import uni from "@dcloudio/vite-plugin-uni";
import { resolve } from "path";
import { readFileSync } from "node:fs";
import VueJsx from "@vitejs/plugin-vue-jsx";
import { networkInterfaces } from "node:os";
import { execSync } from "node:child_process";
// import legacy from '@vitejs/plugin-legacy';
const getLoaclIPV4Address = () => {
const Interfaces = networkInterfaces();
for (let net in Interfaces) {
const inter = Interfaces[net];
if (!inter) continue;
for (let port of inter) {
if (
port.family === "IPv4" &&
!port.internal &&
port.address !== "127.0.0.1"
) {
return port.address;
}
}
}
};
/**
* 配置文件来自 [.env.dev](./.env.dev)
* @param {'dev' | 'prod'} mode
* @returns
*/
const createServerConfig = (mode) => {
if (mode !== "prod") {
const LoaclIPV4Address = getLoaclIPV4Address();
let key: Buffer;
let cert: Buffer;
try {
key = readFileSync(`./${LoaclIPV4Address}-key.pem`);
cert = readFileSync(`./${LoaclIPV4Address}.pem`);
} catch (error) {
// 说明文件不存在,生成对应的证书和密钥
try {
execSync(`mkcert ${LoaclIPV4Address}`);
key = readFileSync(`./${LoaclIPV4Address}-key.pem`);
cert = readFileSync(`./${LoaclIPV4Address}.pem`);
} catch (error) {
/**
* mac: brew install mkcert | mkert 192.168.31.192
* windows: winget mkcert | mkert 192.168.31.192
*/
console.error(
"\x1b[34m" +
"请先安装mkcert " +
" https://github.com/FiloSottile/mkcert" +
"\x1b[39m"
);
console.error(
"\x1b[34m" +
"或者使用其他工具在根目录下生成对应ip的密钥 " +
LoaclIPV4Address +
"\x1b[39m",
"\n"
);
throw error;
}
}
return {
port: 8080,
// h5访问相机权限需要https 可以使用 mkcert在根目录下生成devServer对应ip的证书
https: {
key,
cert,
},
host: "0.0.0.0",
};
} else {
return {};
}
};
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd());
return {
plugins: [uni(), VueJsx()],
build: {
// target: "modules",
outDir: "dist",
assetsDir: "assets",
sourcemap: false,
minify: "terser",
chunkSizeWarningLimit: 1000,
cssTarget: "chrome61",
terserOptions: {
compress: {
defaults: false,
arguments: true,
},
mangle: {
keep_classnames: true,
keep_fnames: true,
},
},
},
server: {
watch: {
ignored: ['**/DumpStack.log.tmp']
}
},
esbuild: {
pure: mode === "dev" ? [] : ["console.log", "debugger"],
},
resolve: {
alias: {
"@": resolve(__dirname, "src"),
},
},
define: {
"import.meta.env": env,
},
css: {
modules: {
localsConvention: "camelCase",
scopeBehaviour: "local",
generateScopedName: "[local]_[hash:6]",
},
preprocessorOptions: {
scss: {
silenceDeprecations: ["legacy-js-api", "color-functions"],
},
},
},
};
});
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mou-haoming/epp-admin-uniapp.git
[email protected]:mou-haoming/epp-admin-uniapp.git
mou-haoming
epp-admin-uniapp
epp-admin-uniapp
master

搜索帮助