vite.config.ts 2.6 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2
import path from 'path'

3 4
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
fxy060608's avatar
fxy060608 已提交
5 6 7 8
import replace from '@rollup/plugin-replace'

import { isCustomElement } from '../uni-shared'

fxy060608's avatar
fxy060608 已提交
9 10 11 12 13 14 15
const moduleAlias = require('module-alias')
moduleAlias.addAlias(
  '@vue/babel-plugin-jsx',
  path.join(__dirname, 'lib/babel-plugin-jsx')
)
const vueJsx = require('@vitejs/plugin-vue-jsx')

fxy060608's avatar
fxy060608 已提交
16 17 18 19
function resolve(file: string) {
  return path.resolve(__dirname, file)
}

20
export default defineConfig({
fxy060608's avatar
fxy060608 已提交
21
  root: __dirname,
fxy060608's avatar
fxy060608 已提交
22 23 24
  define: {
    global: 'window',
    __DEV__: `(process.env.NODE_ENV !== 'production')`,
fxy060608's avatar
fxy060608 已提交
25
    __TEST__: false,
26
    __PLATFORM__: JSON.stringify('h5'),
fxy060608's avatar
fxy060608 已提交
27
    __NODE_JS__: `import.meta.env.SSR`,
fxy060608's avatar
fxy060608 已提交
28
  },
fxy060608's avatar
fxy060608 已提交
29 30 31 32 33 34 35 36 37 38 39 40
  resolve: {
    alias: [
      {
        find: '@dcloudio/uni-api',
        replacement: resolve('../uni-api/src/index.ts'),
      },
      {
        find: '@dcloudio/uni-vue',
        replacement: resolve('../uni-vue/src/index.ts'),
      },
      {
        find: '@dcloudio/uni-core',
fxy060608's avatar
fxy060608 已提交
41
        replacement: resolve('../uni-core/src'),
fxy060608's avatar
fxy060608 已提交
42 43 44 45 46
      },
      {
        find: '@dcloudio/uni-components',
        replacement: resolve('../uni-components/src/index.ts'),
      },
fxy060608's avatar
fxy060608 已提交
47 48 49 50
      {
        find: '@dcloudio/uni-platform',
        replacement: resolve('./src/platform/index.ts'),
      },
fxy060608's avatar
fxy060608 已提交
51 52
    ],
  },
53 54 55 56 57 58 59 60
  plugins: [
    vue({
      template: {
        compilerOptions: {
          isCustomElement,
        },
      },
    }),
fxy060608's avatar
fxy060608 已提交
61
    vueJsx({ optimize: true, isCustomElement }),
62 63 64
  ],
  build: {
    minify: false,
fxy060608's avatar
fxy060608 已提交
65 66 67 68
    lib: {
      entry: path.resolve(__dirname, 'src/index.ts'),
      formats: ['es', 'cjs'],
    },
69 70
    assetsDir: '.',
    rollupOptions: {
fxy060608's avatar
fxy060608 已提交
71
      // input: path.resolve(__dirname, 'src/index.ts'),
fxy060608's avatar
fxy060608 已提交
72 73
      external(source) {
        if (
fxy060608's avatar
fxy060608 已提交
74 75 76 77 78 79 80
          [
            'vue',
            'vue-router',
            '@vue/shared',
            '@dcloudio/uni-i18n',
            '@dcloudio/uni-shared',
          ].includes(source)
fxy060608's avatar
fxy060608 已提交
81 82 83 84 85 86 87
        ) {
          return true
        }
        if (source.startsWith('@dcloudio/uni-h5/style')) {
          return true
        }
      },
88 89
      preserveEntrySignatures: 'strict',
      plugins: [
fxy060608's avatar
fxy060608 已提交
90 91 92 93 94 95 96 97 98 99 100
        // replace({
        //   values: {
        //     // extend: `/*#__PURE__*/ extend`,
        //     // defineOnApi: `/*#__PURE__*/ defineOnApi`,
        //     // defineOffApi: `/*#__PURE__*/ defineOffApi`,
        //     // defineTaskApi: `/*#__PURE__*/ defineTaskApi`,
        //     // defineSyncApi: `/*#__PURE__*/ defineSyncApi`,
        //     // defineAsyncApi: `/*#__PURE__*/ defineAsyncApi`,
        //   },
        //   preventAssignment: true,
        // }),
101
      ],
fxy060608's avatar
fxy060608 已提交
102 103 104
      // output: {
      //   dir: path.resolve(__dirname, 'dist'),
      // },
105
    },
fxy060608's avatar
fxy060608 已提交
106
  },
107
})