From b718d0a338cc1f8a1ab4dfac174fdd53c4f5864b Mon Sep 17 00:00:00 2001
From: schangxiang@126.com <schangxiang@126.com>
Date: 周二, 06 5月 2025 10:10:17 +0800
Subject: [PATCH] 222

---
 HIAWms/web/vite.lib.config.ts |  109 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 109 insertions(+), 0 deletions(-)

diff --git a/HIAWms/web/vite.lib.config.ts b/HIAWms/web/vite.lib.config.ts
new file mode 100644
index 0000000..a76ad4e
--- /dev/null
+++ b/HIAWms/web/vite.lib.config.ts
@@ -0,0 +1,109 @@
+import path from 'path'
+import vue from '@vitejs/plugin-vue'
+import { defineConfig } from 'vite'
+import { buildPlugin } from 'vite-plugin-build'
+import { globSync } from 'glob'
+import { readFileSync, existsSync } from 'fs'
+import cssInjectedByJsPlugin from 'vite-plugin-css-injected-by-js'
+import Components from 'unplugin-vue-components/vite'
+import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
+import VitePluginWidgetProvider from './script/plugins/vite-plugin-widget-provider'
+import vueJsx from '@vitejs/plugin-vue-jsx'
+import { optimizeLodashImports } from '@optimize-lodash/rollup-plugin'
+import dayjs from 'dayjs'
+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> = []
+
+if (isSingleBuild) {
+  const widgetName = readFileSync(argvPath, { encoding: 'utf8' })
+  getWidgetNames.push(widgetName)
+} else {
+  // 鎵ц澶氭牳鍛戒护鎵撳寘
+  if (nodeIndex) {
+    const widgetNameMap = require(path.resolve(process.cwd(), baseBuildFile))
+    getWidgetNames = widgetNameMap[nodeIndex]
+  }
+}
+
+const library: any = getWidgetNames.map((name) => {
+  return {
+    outDir: isWin ? 'D:/syc/CMS Editor/host/wwwroot/widgets' : 'dist',
+    target: 'ES2022',
+    rollupOptions: {
+      external: ['vue', 'sdk'],
+      output: {
+        globals: {
+          vue: 'Vue',
+          sdk: 'sdk',
+        },
+      },
+    },
+    lib: {
+      entry: path.join(__dirname, `./src/widgets/${name}/index.ts`),
+      name: '__importWidgets',
+      formats: ['umd'],
+      fileName: () => {
+        return isWin ? `${name}\\index.js` : `${name}/index.js`
+      },
+    },
+  }
+})
+
+//@ts-ignore
+export default defineConfig(async ({ mode }) => {
+  return {
+    define: {
+      'process.env': process.env,
+      'window.__BUILD_TIME__': `"${dayjs().format('YYYY-MM-DD HH:mm:ss')}"`,
+    },
+    resolve: {
+      alias: {
+        '@': path.resolve(__dirname, 'src'),
+        components: path.resolve(__dirname, './src/components'),
+        sdk: path.resolve(__dirname, 'src/cms/sdk.es.js'),
+      },
+    },
+    publicDir: false,
+
+    plugins: [
+      vueJsx(),
+      vue({
+        reactivityTransform: true,
+      }),
+      VueTypeImports(),
+      VitePluginWidgetProvider(),
+      cssInjectedByJsPlugin(),
+      buildPlugin({
+        fileBuild: false,
+        libBuild: {
+          buildOptions: library,
+        },
+      }),
+      Components({
+        include: [/\.vue$/, /\.vue\?vue/, /\.md$/, /\.tsx/, /\.jsx/],
+        resolvers: [
+          ElementPlusResolver({
+            importStyle: 'sass',
+          }),
+        ],
+      }),
+      optimizeLodashImports(),
+    ],
+    esbuild: {
+      drop: mode !== 'development' ? ['debugger', 'console'] : [],
+    },
+    css: {
+      preprocessorOptions: {
+        scss: {
+          additionalData: `@use "@/assets/styles/element.scss" as *;`,
+        },
+      },
+    },
+  }
+})

--
Gitblit v1.9.3