vite.config.ts 1.7 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')`,
19
    __PLATFORM__: JSON.stringify('h5'),
fxy060608's avatar
fxy060608 已提交
20
  },
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
  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'),
    },
  ],
  plugins: [
    vue({
      template: {
        compilerOptions: {
          isCustomElement,
        },
      },
    }),
  ],
  build: {
    minify: false,
    assetsDir: '.',
    rollupOptions: {
52
      input: path.resolve(__dirname, 'src/index.ts'),
53 54 55 56 57 58 59 60
      external: ['vue', 'vue-router', '@vue/shared', '@dcloudio/uni-shared'],
      preserveEntrySignatures: 'strict',
      plugins: [
        replace({
          createApi: `/*#__PURE__*/ createApi`,
        }),
      ],
      output: {
61
        dir: path.resolve(__dirname, 'dist'),
62
        format: 'es',
63
        manualChunks: undefined,
64 65 66 67 68 69 70 71 72
        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 已提交
73
  },
74
})