build.ts 865 字节
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2 3 4
import path from 'path'
import slash from 'slash'
import { UserConfig } from 'vite'
import { VitePluginUniResolvedOptions } from '..'
fxy060608's avatar
fxy060608 已提交
5
import { initEasycomsOnce } from '../utils'
fxy060608's avatar
fxy060608 已提交
6 7

export function createBuild(
fxy060608's avatar
fxy060608 已提交
8
  options: VitePluginUniResolvedOptions
fxy060608's avatar
fxy060608 已提交
9
): UserConfig['build'] {
fxy060608's avatar
fxy060608 已提交
10
  initEasycomsOnce(options.inputDir, options.platform)
fxy060608's avatar
fxy060608 已提交
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
  return {
    rollupOptions: {
      output: {
        chunkFileNames(chunkInfo) {
          if (chunkInfo.facadeModuleId) {
            const dirname = path.relative(
              options.inputDir,
              path.dirname(chunkInfo.facadeModuleId)
            )
            if (dirname) {
              return `${options.assetsDir}/${slash(dirname).replace(
                /\//g,
                '-'
              )}-[name].[hash].js`
            }
          }
          return '[name].[hash].js'
        },
      },
    },
  }
}