j***@163.com
j***@163.com
  • 发布:2022-09-30 11:18
  • 更新:2024-05-28 12:08
  • 阅读:1794

引入@vitejs/plugin-legacy后运行到APP基座报错

分类:HBuilderX

vite.config.js配置如下:

import legacy from '@vitejs/plugin-legacy'  
import { defineConfig } from 'vite';  
import uni from '@dcloudio/vite-plugin-uni';  
export default defineConfig({  
  plugins: [  
    uni(),  
    legacy({  
      targets: ['defaults', 'not IE 11','chrome > 44']  
    })  
  ]  
})

运行到基座APP报如下错误

error during build:  
11:07:01.118 Error: @vitejs/plugin-legacy does not support library mode.  
11:07:01.122     at Object.configResolved (D:\soft\src\HBuilderX.3.5.3.20220729\HBuilderX\plugins\uniapp-cli-vite\node_modules\@vitejs\plugin-legacy\index.js:179:15)  
11:07:01.126     at D:\soft\src\HBuilderX.3.5.3.20220729\HBuilderX\plugins\uniapp-cli-vite\node_modules\vite\dist\node\chunks\dep-c9998dc6.js:61635:127  
11:07:01.127     at Array.map (<anonymous>)  
11:07:01.131     at resolveConfig (D:\soft\src\HBuilderX.3.5.3.20220729\HBuilderX\plugins\uniapp-cli-vite\node_modules\vite\dist\node\chunks\dep-c9998dc6.js:61635:35)  
11:07:01.131     at processTicksAndRejections (internal/process/task_queues.js:97:5)  
11:07:01.137     at async doBuild (D:\soft\src\HBuilderX.3.5.3.20220729\HBuilderX\plugins\uniapp-cli-vite\node_modules\vite\dist\node\chunks\dep-c9998dc6.js:41564:20)  
11:07:01.142     at async build (D:\soft\src\HBuilderX.3.5.3.20220729\HBuilderX\plugins\uniapp-cli-vite\node_modules\vite\dist\node\chunks\dep-c9998dc6.js:41552:16)  
11:07:01.146     at async buildApp (D:\soft\src\HBuilderX.3.5.3.20220729\HBuilderX\plugins\uniapp-cli-vite\node_modules\@dcloudio\vite-plugin-uni\dist\cli\build.js:100:25)  
11:07:01.151     at async CAC.runDev (D:\soft\src\HBuilderX.3.5.3.20220729\HBuilderX\plugins\uniapp-cli-vite\node_modules\@dcloudio\vite-plugin-uni\dist\cli\action.js:28:30)

运行到浏览器是可以的。

2022-09-30 11:18 负责人:无 分享
已邀请:
2***@qq.com

2***@qq.com

哥们,解决了吗,一样的问题

  • 1***@163.com

    我也遇到这问题,请问怎么解决的

    3051813192

    QQ请联系,红包奖励

    2023-06-06 16:30

1***@163.com

1***@163.com - webuy

Error: @vitejs/plugin-legacy does not support library mode.

1***@qq.com

1***@qq.com

DCloud 人呢???

6***@qq.com

6***@qq.com

什么鬼?为什么这么久了官方还没回复

guyskk

guyskk - https://blog.guyskk.com 艺爪AI、自宅创业

可以在 vite.config.js 里面用 process.env.UNI_PLATFORM 判断禁用插件。

import uni from '@dcloudio/vite-plugin-uni'  
import legacyPlugin from '@vitejs/plugin-legacy'  
import { visualizer as bundleVisualizer } from 'rollup-plugin-visualizer'  
import { defineConfig } from 'vite'  
import eslintPlugin from 'vite-plugin-eslint'  

const platform = process.env.UNI_PLATFORM  
const isH5 = platform === 'h5'  

function definePlugins() {  
  const plugins = [uni(), eslintPlugin()]  
  if (isH5) {  
    plugins.push(legacyPlugin())  
    plugins.push(  
      bundleVisualizer({  
        emitFile: true,  
        gzipSize: true,  
        filename: 'bundle-visualizer.html',  
      })  
    )  
  }  
  return plugins  
}  

// https://vitejs.dev/config/  
export default defineConfig({  
  plugins: definePlugins(),  
})

要回复问题请先登录注册