zs
2025-04-28 1f32ea02c1910c417f159cba81a296e66ae7484c
HIAWms/web/vite.lib.config.ts
文件名从 WMS/web/vite.lib.config.ts 修改
@@ -14,21 +14,33 @@
import VueTypeImports from 'vite-plugin-vue-type-imports'
const execa = require('execa')
const isWin = process.platform === 'win32'
const argvPath: string = './script/.argv'
const isSingleBuild = existsSync(argvPath)
const nodeIndex = process.env.NODE_INDEX
const baseBuildFile = './node_modules/.cache/widgets.json'
let getWidgetNames: Array<string> = []
const argvPath: string = './script/.argv'
const isAllBuild = existsSync(argvPath)
if (isSingleBuild) {
function getGitHash() {
  return execa('git', ['rev-parse', '--short', 'HEAD'])
}
function getGitBranch() {
  return execa('git', ['rev-parse', '--abbrev-ref', 'HEAD'])
}
function getGitUserName() {
  return execa('git', ['config', 'user.name'])
}
if (isAllBuild) {
  const widgetName = readFileSync(argvPath, { encoding: 'utf8' })
  getWidgetNames.push(widgetName)
} else {
  // 鎵ц澶氭牳鍛戒护鎵撳寘
  if (nodeIndex) {
    const widgetNameMap = require(path.resolve(process.cwd(), baseBuildFile))
    getWidgetNames = widgetNameMap[nodeIndex]
  }
  const widgetsPath = globSync(`./src/widgets/*/index.ts`)
  getWidgetNames = widgetsPath.map((file) => {
    const parts = isWin
      ? path.resolve(file).split('\\')
      : path.resolve(file).split('/')
    return parts[parts.length - 2]
  })
}
const library: any = getWidgetNames.map((name) => {
@@ -57,10 +69,24 @@
//@ts-ignore
export default defineConfig(async ({ mode }) => {
  let commit
  let branch
  let userName
  try {
    commit = await getGitHash()
    branch = await getGitBranch()
    userName = await getGitUserName()
  } catch (e) {
    console.log(e)
  }
  return {
    define: {
      'process.env': process.env,
      'window.__BUILD_TIME__': `"${dayjs().format('YYYY-MM-DD HH:mm:ss')}"`,
      'window.__COMMIT__': `"${commit?.stdout}"`,
      'window.__BRANCH__': `"${branch?.stdout}"`,
      'window.__USER_NAME__': `"${userName?.stdout}"`,
    },
    resolve: {
      alias: {