options.ts 3.2 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1
import path from 'path'
fxy060608's avatar
fxy060608 已提交
2
import { CompilerOptions, NodeTypes } from '@vue/compiler-core'
fxy060608's avatar
fxy060608 已提交
3 4
import {
  COMPONENT_ON_LINK,
fxy060608's avatar
fxy060608 已提交
5
  copyMiniProgramPluginJson,
fxy060608's avatar
fxy060608 已提交
6
  createTransformComponentLink,
fxy060608's avatar
fxy060608 已提交
7
  MiniProgramCompilerOptions,
fxy060608's avatar
fxy060608 已提交
8
  transformMatchMedia,
fxy060608's avatar
fxy060608 已提交
9 10 11
} from '@dcloudio/uni-cli-shared'
import { UniMiniProgramPluginOptions } from '@dcloudio/uni-mp-vite'
import source from './mini.project.json'
fxy060608's avatar
fxy060608 已提交
12
import { transformRef } from './transforms/transformRef'
fxy060608's avatar
fxy060608 已提交
13
import { event } from './event'
fxy060608's avatar
fxy060608 已提交
14
import { transformOpenType } from './transforms/transformOpenType'
fxy060608's avatar
fxy060608 已提交
15 16

const projectConfigFilename = 'mini.project.json'
fxy060608's avatar
fxy060608 已提交
17

fxy060608's avatar
fxy060608 已提交
18
export const miniProgram: MiniProgramCompilerOptions = {
fxy060608's avatar
fxy060608 已提交
19
  event,
fxy060608's avatar
fxy060608 已提交
20 21 22 23
  class: {
    array: false,
  },
  slot: {
fxy060608's avatar
fxy060608 已提交
24
    $slots: false,
fxy060608's avatar
fxy060608 已提交
25
    // 支付宝 fallback 有 bug,当多个带默认 slot 组件嵌套使用时,所有的默认slot均会显示,如uni-file-picker(image)
fxy060608's avatar
fxy060608 已提交
26
    fallbackContent: true,
27
    dynamicSlotNames: true,
fxy060608's avatar
fxy060608 已提交
28 29 30
  },
  directive: 'a:',
}
fxy060608's avatar
fxy060608 已提交
31
const nodeTransforms = [
fxy060608's avatar
fxy060608 已提交
32
  transformRef,
fxy060608's avatar
fxy060608 已提交
33
  transformOpenType,
fxy060608's avatar
fxy060608 已提交
34
  transformMatchMedia,
fxy060608's avatar
fxy060608 已提交
35 36
  createTransformComponentLink(COMPONENT_ON_LINK, NodeTypes.ATTRIBUTE),
]
fxy060608's avatar
fxy060608 已提交
37 38 39 40
export const compilerOptions: CompilerOptions = {
  nodeTransforms,
}

fxy060608's avatar
fxy060608 已提交
41
export const customElements = [
fxy060608's avatar
fxy060608 已提交
42 43 44 45 46 47 48 49 50 51 52 53
  'lifestyle',
  'life-follow',
  'contact-button',
  'spread',
  'error-view',
  'poster',
  'cashier',
  'ix-grid',
  'ix-native-grid',
  'ix-native-list',
  'mkt',
]
fxy060608's avatar
fxy060608 已提交
54

fxy060608's avatar
fxy060608 已提交
55 56 57 58 59 60 61 62 63 64
export const options: UniMiniProgramPluginOptions = {
  vite: {
    inject: {
      uni: [path.resolve(__dirname, 'uni.api.esm.js'), 'default'],
    },
    alias: {
      'uni-mp-runtime': path.resolve(__dirname, 'uni.mp.esm.js'),
    },
    copyOptions: {
      assets: ['mycomponents'],
fxy060608's avatar
fxy060608 已提交
65
      targets: process.env.UNI_MP_PLUGIN ? [copyMiniProgramPluginJson] : [],
fxy060608's avatar
fxy060608 已提交
66 67 68
    },
  },
  global: 'my',
fxy060608's avatar
fxy060608 已提交
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
  json: {
    windowOptionsMap: {
      defaultTitle: 'navigationBarTitleText',
      pullRefresh: 'enablePullDownRefresh',
      allowsBounceVertical: 'allowsBounceVertical',
      titleBarColor: 'navigationBarBackgroundColor',
      optionMenu: 'optionMenu',
      backgroundColor: 'backgroundColor',
      usingComponents: 'usingComponents',
      navigationBarShadow: 'navigationBarShadow',
      titleImage: 'titleImage',
      transparentTitle: 'transparentTitle',
      titlePenetrate: 'titlePenetrate',
    },
    tabBarOptionsMap: {
      textColor: 'color',
      selectedColor: 'selectedColor',
      backgroundColor: 'backgroundColor',
      items: 'list',
    },
    tabBarItemOptionsMap: {
      pagePath: 'pagePath',
      name: 'text',
      icon: 'iconPath',
      activeIcon: 'selectedIconPath',
    },
  },
fxy060608's avatar
fxy060608 已提交
96 97 98
  app: {
    darkmode: false,
    subpackages: true,
fxy060608's avatar
fxy060608 已提交
99
    plugins: true,
fxy060608's avatar
fxy060608 已提交
100 101 102 103 104 105
  },
  project: {
    filename: projectConfigFilename,
    source,
  },
  template: {
fxy060608's avatar
fxy060608 已提交
106 107
    /* eslint-disable no-restricted-syntax */
    ...miniProgram,
fxy060608's avatar
fxy060608 已提交
108
    customElements,
fxy060608's avatar
fxy060608 已提交
109 110 111 112
    filter: {
      extname: '.sjs',
      lang: 'sjs',
      generate(filter, filename) {
fxy060608's avatar
fxy060608 已提交
113 114 115
        // TODO 标签内的 code 代码需要独立生成一个 sjs 文件
        // 暂不处理,让开发者自己全部使用 src 引入
        return `<import-sjs name="${filter.name}" from="${filename}.sjs"/>`
fxy060608's avatar
fxy060608 已提交
116 117 118
      },
    },
    extname: '.axml',
fxy060608's avatar
fxy060608 已提交
119
    compilerOptions,
fxy060608's avatar
fxy060608 已提交
120 121 122 123 124
  },
  style: {
    extname: '.acss',
  },
}