1+ import { createRequire } from 'node:module'
2+ import { dirname } from 'node:path'
3+ import { fileURLToPath } from 'node:url'
4+
15import uni from '@dcloudio/vite-plugin-uni'
26import AutoImport from 'unplugin-auto-import/vite'
37import { defineConfig } from 'vite'
48import { UnifiedViteWeappTailwindcssPlugin as uvtw } from 'weapp-tailwindcss/vite'
59import { WeappTailwindcssDisabled } from './platform'
610import postcssPlugins from './postcss.config.cjs'
711
12+ const require = createRequire ( import . meta. url )
13+ const here = dirname ( fileURLToPath ( import . meta. url ) )
14+ const mpWeixinDir = dirname (
15+ require . resolve ( '@dcloudio/uni-mp-weixin/package.json' , { paths : [ here ] } ) ,
16+ )
17+ // Resolve vue runtime from the same version bundled with mp-weixin to avoid older 2.x builds lacking findComponentPropsData
18+ const uniMpVueRuntimePath = require . resolve ( '@dcloudio/uni-mp-vue/dist/vue.runtime.esm.js' , {
19+ paths : [ mpWeixinDir , here ] ,
20+ } )
21+ const uniMpVueDir = dirname ( uniMpVueRuntimePath )
22+
823// https://vitejs.dev/config/
924export default defineConfig ( {
1025 // uvtw 一定要放在 uni 后面
1126 plugins : [
27+ {
28+ name : 'force-uni-mp-vue-runtime' ,
29+ enforce : 'pre' ,
30+ resolveId ( id ) {
31+ if (
32+ id === 'vue' ||
33+ id === '@dcloudio/uni-mp-vue' ||
34+ id === '@dcloudio/uni-mp-vue/dist/vue.runtime.esm.js'
35+ ) {
36+ return uniMpVueRuntimePath
37+ }
38+ } ,
39+ } ,
1240 uni ( ) ,
1341 uvtw ( {
1442 rem2rpx : true ,
@@ -35,4 +63,12 @@ export default defineConfig({
3563 } ,
3664 } ,
3765 } ,
66+ resolve : {
67+ alias : {
68+ vue : uniMpVueRuntimePath ,
69+ // Ensure we always consume the Vue 3 runtime that exposes findComponentPropsData
70+ '@dcloudio/uni-mp-vue/dist/vue.runtime.esm.js' : uniMpVueRuntimePath ,
71+ '@dcloudio/uni-mp-vue' : uniMpVueDir ,
72+ } ,
73+ } ,
3874} )
0 commit comments