options.ts 1.7 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1
import path from 'path'
fxy060608's avatar
fxy060608 已提交
2 3
import type { CompilerOptions } from '@vue/compiler-core'
import { isCustomElement, isNativeTag } from '@dcloudio/uni-shared'
4
import {
fxy060608's avatar
fxy060608 已提交
5
  MiniProgramCompilerOptions,
fxy060608's avatar
fxy060608 已提交
6 7
  transformComponentLink,
  transformMatchMedia,
fxy060608's avatar
fxy060608 已提交
8
  transformRef,
9
} from '@dcloudio/uni-cli-shared'
fxy060608's avatar
fxy060608 已提交
10 11 12
import { UniMiniProgramPluginOptions } from '@dcloudio/uni-mp-vite'

import source from './project.config.json'
fxy060608's avatar
fxy060608 已提交
13
import { transformSwiper } from './transforms/transformSwiper'
fxy060608's avatar
fxy060608 已提交
14 15 16

const projectConfigFilename = 'project.config.json'

fxy060608's avatar
fxy060608 已提交
17
const nodeTransforms = [
fxy060608's avatar
fxy060608 已提交
18 19
  transformRef,
  transformSwiper,
fxy060608's avatar
fxy060608 已提交
20 21
  transformMatchMedia,
  transformComponentLink,
fxy060608's avatar
fxy060608 已提交
22
]
fxy060608's avatar
fxy060608 已提交
23 24 25 26 27 28

export const compilerOptions: CompilerOptions = {
  isNativeTag,
  isCustomElement,
  nodeTransforms,
}
fxy060608's avatar
fxy060608 已提交
29 30 31 32 33 34 35 36 37 38
export const miniProgram: MiniProgramCompilerOptions = {
  class: {
    array: false,
  },
  slot: {
    fallback: true,
  },
  directive: 'tt:',
}

fxy060608's avatar
fxy060608 已提交
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
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: ['ttcomponents'],
    },
  },
  global: 'tt',
  app: {
    darkmode: false,
    subpackages: true,
  },
  project: {
    filename: projectConfigFilename,
    source,
  },
  template: {
fxy060608's avatar
fxy060608 已提交
61 62
    /* eslint-disable no-restricted-syntax */
    ...miniProgram,
fxy060608's avatar
fxy060608 已提交
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
    filter: {
      extname: '.sjs',
      lang: 'sjs',
      generate(filter, filename) {
        if (filename) {
          return `<sjs src="${filename}.sjs" module="${filter.name}"/>`
        }
        return `<sjs module="${filter.name}">
${filter.code}
</sjs>`
      },
    },
    extname: '.ttml',
  },
  style: {
    extname: '.ttss',
  },
}