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

3 4 5
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

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 34 35 36 37 38 39 40 41
  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',
        replacement: resolve('../uni-core/src/index.ts'),
      },
      {
        find: '@dcloudio/uni-components',
        replacement: resolve('../uni-components/src/index.ts'),
      },
    ],
  },
42 43 44 45 46 47 48 49 50 51 52 53 54
  plugins: [
    vue({
      template: {
        compilerOptions: {
          isCustomElement,
        },
      },
    }),
  ],
  build: {
    minify: false,
    assetsDir: '.',
    rollupOptions: {
55
      input: path.resolve(__dirname, 'src/index.ts'),
56 57 58 59
      external: ['vue', 'vue-router', '@vue/shared', '@dcloudio/uni-shared'],
      preserveEntrySignatures: 'strict',
      plugins: [
        replace({
60 61 62 63 64 65 66
          values: {
            createOnApi: `/*#__PURE__*/ createOnApi`,
            createTaskApi: `/*#__PURE__*/ createTaskApi`,
            createSyncApi: `/*#__PURE__*/ createSyncApi`,
            createAsyncApi: `/*#__PURE__*/ createAsyncApi`,
          },
          preventAssignment: true,
67 68 69
        }),
      ],
      output: {
70
        dir: path.resolve(__dirname, 'dist'),
71
        format: 'es',
72
        manualChunks: undefined,
73 74 75 76 77 78 79 80 81
        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 已提交
82
  },
83
})