build(vite): 优化不同环境下的配置

This commit is contained in:
Burt 2024-01-04 10:43:38 +08:00
parent 8b5d543fc9
commit 20c9976025

View File

@ -17,6 +17,7 @@ import autoprefixer from 'autoprefixer'
/** 这个修改只对web生效小程序没有index.html这个文件 */ /** 这个修改只对web生效小程序没有index.html这个文件 */
const htmlPlugin = (title: string) => { const htmlPlugin = (title: string) => {
console.log('---htmlPlugin---')
return { return {
name: 'html-transform', name: 'html-transform',
transformIndexHtml(html) { transformIndexHtml(html) {
@ -40,13 +41,14 @@ export default ({ command, mode }) => {
// loadEnv(): 返回当前环境env文件中额外定义的变量 // loadEnv(): 返回当前环境env文件中额外定义的变量
const env = loadEnv(mode, path.resolve(process.cwd(), 'env')) const env = loadEnv(mode, path.resolve(process.cwd(), 'env'))
console.log(env) console.log(env)
console.log(process.env.UNI_PLATFORM) // 得到 mp-weixin, h5 等
return defineConfig({ return defineConfig({
plugins: [ plugins: [
// UniPages() 需要在 Uni() 之前引入 // UniPages() 需要在 Uni() 之前引入
UniPages(), UniPages(),
Uni(), Uni(),
UnoCSS(), UnoCSS(),
htmlPlugin(env.VITE_APP_TITLE), process.env.UNI_PLATFORM === 'h5' && htmlPlugin(env.VITE_APP_TITLE),
svgLoader(), svgLoader(),
// 打包分析插件 // 打包分析插件
mode === 'production' && mode === 'production' &&