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

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

fxy060608's avatar
fxy060608 已提交
16
export const miniProgram: MiniProgramCompilerOptions = {
fxy060608's avatar
fxy060608 已提交
17
  event,
fxy060608's avatar
fxy060608 已提交
18 19 20 21
  class: {
    array: false,
  },
  slot: {
fxy060608's avatar
fxy060608 已提交
22
    $slots: true,
fxy060608's avatar
fxy060608 已提交
23 24
    // 支付宝 fallback 有 bug,当多个带默认 slot 组件嵌套使用时,所有的默认slot均会显示,如uni-file-picker(image)
    fallback: false,
fxy060608's avatar
fxy060608 已提交
25 26 27
  },
  directive: 'a:',
}
fxy060608's avatar
fxy060608 已提交
28
// TODO getPhoneNumber 等事件
fxy060608's avatar
fxy060608 已提交
29 30
export const nodeTransforms = [
  transformRef,
fxy060608's avatar
fxy060608 已提交
31
  transformOpenType,
fxy060608's avatar
fxy060608 已提交
32 33
  createTransformComponentLink(COMPONENT_ON_LINK, NodeTypes.ATTRIBUTE),
]
fxy060608's avatar
fxy060608 已提交
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
export const tags = [
  'lifestyle',
  'life-follow',
  'contact-button',
  'spread',
  'error-view',
  'poster',
  'cashier',
  'ix-grid',
  'ix-native-grid',
  'ix-native-list',
  'mkt',
]
export function isCustomElement(tag: string) {
  return tags.includes(tag)
}
fxy060608's avatar
fxy060608 已提交
50 51 52 53 54 55 56 57 58 59 60 61 62
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'],
    },
  },
  global: 'my',
fxy060608's avatar
fxy060608 已提交
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
  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 已提交
90 91 92 93 94 95 96 97 98
  app: {
    darkmode: false,
    subpackages: true,
  },
  project: {
    filename: projectConfigFilename,
    source,
  },
  template: {
fxy060608's avatar
fxy060608 已提交
99 100
    /* eslint-disable no-restricted-syntax */
    ...miniProgram,
fxy060608's avatar
fxy060608 已提交
101 102 103 104
    filter: {
      extname: '.sjs',
      lang: 'sjs',
      generate(filter, filename) {
fxy060608's avatar
fxy060608 已提交
105 106 107
        // TODO 标签内的 code 代码需要独立生成一个 sjs 文件
        // 暂不处理,让开发者自己全部使用 src 引入
        return `<import-sjs name="${filter.name}" from="${filename}.sjs"/>`
fxy060608's avatar
fxy060608 已提交
108 109 110 111
      },
    },
    extname: '.axml',
    compilerOptions: {
fxy060608's avatar
fxy060608 已提交
112
      isCustomElement,
fxy060608's avatar
fxy060608 已提交
113
      nodeTransforms,
fxy060608's avatar
fxy060608 已提交
114 115 116 117 118 119
    },
  },
  style: {
    extname: '.acss',
  },
}