mh-two-thousand-and-two
2024-04-12 3d2ec2fd0578d3ba0a414b0cc4e4a2ae60878596
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const fs = require('fs')
const path = require('path')
const { parseJson } = require('@dcloudio/uni-cli-shared/lib/json')
const { copyMiniProgramThemeJson } = require('@dcloudio/uni-cli-shared/lib/theme')
 
const COMPONENTS_DIR_NAME = 'wxcomponents'
 
module.exports = {
  options: {
    cssVars: {
      '--status-bar-height': '25px',
      '--window-top': '0px',
      '--window-bottom': '0px',
      '--window-left': '0px',
      '--window-right': '0px'
    },
    extnames: {
      style: '.wxss',
      template: '.wxml',
      filter: '.wxs'
    },
    filterTag: 'wxs',
    project: 'project.config.json',
    subPackages: true,
    darkmode: true
  },
  copyWebpackOptions (platformOptions, vueOptions) {
    const CopyWebpackPluginVersion = Number(require('copy-webpack-plugin/package.json').version.split('.')[0])
    const copyOptions = [
      'sitemap.json',
      'ext.json',
      'custom-tab-bar',
      'functional-pages',
      'project.private.config.json'
    ]
 
    if (process.env.UNI_MP_PLUGIN) {
      copyOptions.push({
        from: path.resolve(process.env.UNI_INPUT_DIR, 'plugin.json'),
        transform: content => JSON.stringify(parseJson(content.toString(), true))
      })
    }
 
    copyOptions.push(copyMiniProgramThemeJson(platformOptions, vueOptions))
 
    const workers = platformOptions.workers
    workers && copyOptions.push(typeof workers === 'object' ? workers.path : workers)
 
    const manifestConfig = process.UNI_MANIFEST
    const weixinConfig = manifestConfig['mp-weixin'] || {}
    const copyWxComponentsOnDemandSwitch = !!weixinConfig.copyWxComponentsOnDemand // 默认值false
    const ignore = ['**/*.vue', '**/*.css'] // v3 会自动转换生成vue,css文件,需要过滤
 
    if (!copyWxComponentsOnDemandSwitch) {
      const wxcomponentsDir = path.resolve(process.env.UNI_INPUT_DIR, COMPONENTS_DIR_NAME)
      if (fs.existsSync(wxcomponentsDir)) {
        copyOptions.push(Object.assign({
          from: wxcomponentsDir,
          to: COMPONENTS_DIR_NAME
        }, CopyWebpackPluginVersion > 5 ? {
          globOptions: { ignore }
        } : {
          ignore
        }))
      }
    }
    global.uniModules.forEach(module => {
      const wxcomponentsDir = path.resolve(process.env.UNI_INPUT_DIR, 'uni_modules', module, COMPONENTS_DIR_NAME)
      if (fs.existsSync(wxcomponentsDir)) {
        copyOptions.push(Object.assign({
          from: wxcomponentsDir,
          to: 'uni_modules/' + module + '/' + COMPONENTS_DIR_NAME
        }, CopyWebpackPluginVersion > 5 ? {
          globOptions: { ignore }
        } : {
          ignore
        }))
      }
    })
    return copyOptions
  }
}