dcloudio / uni-preset-vue

uni-app preset for vue
Apache License 2.0
300 stars 116 forks source link

vite-ts 模板构建的项目,添加 @vitejs/plugin-legacy 插件后无法构建微信小程序 #99

Open PurpleNoon opened 4 months ago

PurpleNoon commented 4 months ago

使用 vite-ts 模板构建,添加 @vitejs/plugin-legacy 插件后,无法构建微信小程序(h5 的可以正常构建),由于报错时没有给出详细的错误信息输出,无法确定问题出在哪里 错误信息输出如下:

> uni-preset-vue@0.0.0 build:mp-weixin E:\qge\proj\other\uniapp-ts\legacy-test
> uni build -p mp-weixin

正在编译中...

uni-app 有新版本发布,请执行 `npx @dcloudio/uvm@latest` 更新,更新日志详见:https://download1.dcloud.net.cn/hbuilderx/changelog/4.15.2024050802.html
Build failed with errors.
 ELIFECYCLE  Command failed with exit code 1.

项目信息:

复现项目地址:https://github.com/PurpleNoon/uni-ts-legacy-plugin

完整复现步骤

  1. 使用官网命令拉取 vite-ts 模板并安装依赖
    npx degit dcloudio/uni-preset-vue#vite-ts my-vue3-project
    cd ./my-vue3-project
    pnpm i
  2. 安装 @vitejs/plugin-legacy
    pnpm i -D @vitejs/plugin-legacy
  3. vite.config.ts 修改相关代码,并添加 .browserslistrc 文件(没有该文件时同样无法构建)
    
    // vite.config.ts
    import { defineConfig } from "vite";
    import uni from "@dcloudio/vite-plugin-uni";
    import legacy from '@vitejs/plugin-legacy'

// https://vitejs.dev/config/ export default defineConfig({ plugins: [ uni(), legacy(), ], });


4. 执行 `pnpm run build:mp-weixin` 即可复现
PurpleNoon commented 4 months ago

补充: 操作系统:Win10