uni.config.js 2.1 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2
const fs = require('fs')
const path = require('path')
3
const { parseJson } = require('@dcloudio/uni-cli-shared/lib/json')
fxy060608's avatar
fxy060608 已提交
4 5 6 7 8 9 10 11

const COMPONENTS_DIR_NAME = 'wxcomponents'

module.exports = {
  options: {
    cssVars: {
      '--status-bar-height': '25px',
      '--window-top': '0px',
fxy060608's avatar
fxy060608 已提交
12 13
      '--window-bottom': '0px',
      '--window-left': '0px',
fxy060608's avatar
fxy060608 已提交
14
      '--window-right': '0px'
fxy060608's avatar
fxy060608 已提交
15 16 17 18 19 20 21 22
    },
    extnames: {
      style: '.wxss',
      template: '.wxml',
      filter: '.wxs'
    },
    filterTag: 'wxs',
    project: 'project.config.json',
fxy060608's avatar
fxy060608 已提交
23 24
    subPackages: true,
    darkmode: true
fxy060608's avatar
fxy060608 已提交
25 26
  },
  copyWebpackOptions (platformOptions, vueOptions) {
fxy060608's avatar
fxy060608 已提交
27
    const copyOptions = [
fxy060608's avatar
fxy060608 已提交
28
      'theme.json',
fxy060608's avatar
fxy060608 已提交
29 30
      'sitemap.json',
      'ext.json',
31
      'custom-tab-bar',
fxy060608's avatar
fxy060608 已提交
32
      'functional-pages'
fxy060608's avatar
fxy060608 已提交
33
    ]
D
DCloud_LXH 已提交
34

35 36 37 38 39 40 41
    JSON.parse(process.env.UNI_MP_PLUGIN_EXPORT)
      .concat(process.env.UNI_MP_PLUGIN ? 'plugin.json' : undefined)
      .forEach(fileName => {
        fileName && copyOptions.push({
          from: path.resolve(process.env.UNI_INPUT_DIR, fileName),
          transform: content => fileName === 'plugin.json' ? JSON.stringify(parseJson(content.toString(), true)) : content
        })
42
      })
D
DCloud_LXH 已提交
43

fxy060608's avatar
fxy060608 已提交
44 45 46 47 48 49 50 51 52 53 54
    const workers = platformOptions.workers
    workers && copyOptions.push(workers)

    const wxcomponentsDir = path.resolve(process.env.UNI_INPUT_DIR, COMPONENTS_DIR_NAME)
    if (fs.existsSync(wxcomponentsDir)) {
      copyOptions.push({
        from: wxcomponentsDir,
        to: COMPONENTS_DIR_NAME,
        ignore: ['**/*.vue', '**/*.css'] // v3 会自动转换生成vue,css文件,需要过滤
      })
    }
fxy060608's avatar
fxy060608 已提交
55 56 57 58 59 60 61 62 63 64
    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({
          from: wxcomponentsDir,
          to: 'uni_modules/' + module + '/' + COMPONENTS_DIR_NAME,
          ignore: ['**/*.vue', '**/*.css'] // v3 会自动转换生成vue,css文件,需要过滤
        })
      }
    })
fxy060608's avatar
fxy060608 已提交
65 66
    return copyOptions
  }
67
}