vite.config.ts 2.3 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
import vueJsx from '@vitejs/plugin-vue-jsx'
fxy060608's avatar
fxy060608 已提交
6 7 8 9 10 11 12 13
import replace from '@rollup/plugin-replace'

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

function resolve(file: string) {
  return path.resolve(__dirname, file)
}

14
export default defineConfig({
fxy060608's avatar
fxy060608 已提交
15 16 17 18
  root: '.',
  define: {
    global: 'window',
    __DEV__: `(process.env.NODE_ENV !== 'production')`,
fxy060608's avatar
fxy060608 已提交
19
    __TEST__: false,
20
    __PLATFORM__: JSON.stringify('h5'),
fxy060608's avatar
fxy060608 已提交
21
  },
fxy060608's avatar
fxy060608 已提交
22 23 24 25 26 27 28 29 30 31 32 33
  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 已提交
34
        replacement: resolve('../uni-core/src'),
fxy060608's avatar
fxy060608 已提交
35 36 37 38 39 40 41
      },
      {
        find: '@dcloudio/uni-components',
        replacement: resolve('../uni-components/src/index.ts'),
      },
    ],
  },
42 43 44 45 46 47 48 49
  plugins: [
    vue({
      template: {
        compilerOptions: {
          isCustomElement,
        },
      },
    }),
fxy060608's avatar
fxy060608 已提交
50
    vueJsx({ optimize: true, isCustomElement }),
51 52 53 54 55
  ],
  build: {
    minify: false,
    assetsDir: '.',
    rollupOptions: {
56
      input: path.resolve(__dirname, 'src/index.ts'),
fxy060608's avatar
fxy060608 已提交
57 58 59 60 61 62 63 64 65 66 67 68
      external(source) {
        if (
          ['vue', 'vue-router', '@vue/shared', '@dcloudio/uni-shared'].includes(
            source
          )
        ) {
          return true
        }
        if (source.startsWith('@dcloudio/uni-h5/style')) {
          return true
        }
      },
69 70 71
      preserveEntrySignatures: 'strict',
      plugins: [
        replace({
72 73 74 75 76 77 78
          values: {
            createOnApi: `/*#__PURE__*/ createOnApi`,
            createTaskApi: `/*#__PURE__*/ createTaskApi`,
            createSyncApi: `/*#__PURE__*/ createSyncApi`,
            createAsyncApi: `/*#__PURE__*/ createAsyncApi`,
          },
          preventAssignment: true,
79 80 81
        }),
      ],
      output: {
82
        dir: path.resolve(__dirname, 'dist'),
83
        format: 'es',
84
        manualChunks: undefined,
85 86 87 88 89 90 91 92 93
        entryFileNames: 'uni-h5.esm.js',
        assetFileNames(assetInfo) {
          if (assetInfo.name === 'style.css') {
            return 'uni-h5.css'
          }
          return 'assets/[name]-[hash][extname]'
        },
      },
    },
fxy060608's avatar
fxy060608 已提交
94
  },
95
})