gaoluyang
2026-11-03 2d8b1a28fa5c8b852f0d0078bac4894bfb4abed5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { defineConfig } from 'vite';
import uni from '@dcloudio/vite-plugin-uni';
 
function uniH5ReadonlySlotPatch() {
  return {
    name: 'uni-h5-readonly-slot-patch',
    enforce: 'post',
    transform(code, id) {
      if (!id.includes('@dcloudio/uni-h5-vue') || !id.endsWith('vue.runtime.esm.js')) {
        return null;
      }
      if (!code.includes('const updateSlots = (instance, children, optimized) => {')) {
        return null;
      }
      const helper = `
const extendSlots = (slots, children) => {
  for (const key in children) {
    if (key === "_") {
      const descriptor = Object.getOwnPropertyDescriptor(slots, key);
      if (descriptor && descriptor.writable === false) {
        Object.defineProperty(slots, key, {
          value: children[key],
          configurable: true,
          enumerable: descriptor.enumerable,
          writable: true
        });
        continue;
      }
    }
    slots[key] = children[key];
  }
};
`;
      return code
        .replace('const updateSlots = (instance, children, optimized) => {', `${helper}\nconst updateSlots = (instance, children, optimized) => {`)
        .replaceAll('extend(slots, children);', 'extendSlots(slots, children);');
    },
  };
}
 
export default defineConfig({
  plugins: [uni(), uniH5ReadonlySlotPatch()],
  build: {
    target: 'es2015',
  },
  server: {
    proxy: {
      '/admin-api': {
        target: 'http://36.213.90.123:9500',
        changeOrigin: true,
      },
    },
  },
});