对比新文件 |
| | |
| | | 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 *;`, |
| | | }, |
| | | }, |
| | | }, |
| | | } |
| | | }) |