如果是调试环境 是可以正常运行 打包就会报这个
H5 APP 小程序都一样 调试环境可以运行 发布就报错
vite.config.js
import {
defineConfig
} from 'vite';
import uni from '@dcloudio/vite-plugin-uni';
const fs = require('fs')
import { resolve } from 'path'
const loadEnv = (name = '') => {
const prefixRE = /^VUE_APP_/
const envs = {};
const env = fs.readFileSync(`${__dirname}/.env${name}`, 'UTF-8');
const arr = env.split("\r\n");
arr.forEach(e => {
if (e.trim()) {
const s = e.split("=");
if (prefixRE.test(s[0])) {
envs[s[0]] = s[1];
}
}
});
return envs;
}
const envs = () => {
const allEnvs = {};
Object.assign(allEnvs, loadEnv(''));
let env = '.private';
if (process.env.NODE_ENV === 'production') {
env = '.prod'
}
Object.assign(allEnvs, loadEnv(env));
return allEnvs;
}
export default defineConfig({
plugins: [
uni()
],
define: {
'process.env': envs()
},
css: {
preprocessorOptions: {
scss: {
additionalData: '@import "@/styles/index.scss";'
}
}
},
/*
build: {
minify: 'terser',
terserOptions: {
compress: {
drop_console: true,
},
},
},*/
});
8***@qq.com
解决了吗,兄弟
2024-07-24 11:49