| | |
| | | import path from 'path' |
| | | import vue from '@vitejs/plugin-vue' |
| | | import { defineConfig } from 'vite' |
| | | import { defineConfig, loadEnv } from 'vite' |
| | | import { buildPlugin } from 'vite-plugin-build' |
| | | import { globSync } from 'glob' |
| | | import { readFileSync, existsSync } from 'fs' |
| | |
| | | import Components from 'unplugin-vue-components/vite' |
| | | import { ElementPlusResolver } from 'unplugin-vue-components/resolvers' |
| | | import VitePluginWidgetProvider from './script/plugins/vite-plugin-widget-provider' |
| | | import VitePluginDevelopmentFilter from './script/plugins/vite-plugin-development-filter' |
| | | import vitePluginImageFilter from './script/plugins/vite-plugin-image-filter' |
| | | 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') |
| | | import svgIcon from 'vite-plugin-svgicon' |
| | | import { vitePluginForArco } from '@arco-plugins/vite-vue' |
| | | import slash from 'slash' |
| | | const isWin = process.platform === 'win32' |
| | | const isCustom = process.env.NODE_TYPE === 'custom' |
| | | const argvPath: string = './script/.argv' |
| | | const isSingleBuild = existsSync(argvPath) |
| | | const tag = 'information-debugger' |
| | | const nodeIndex = process.env.NODE_INDEX |
| | | const baseBuildFile = './node_modules/.cache/widgets.json' |
| | | |
| | | let getWidgetNames: Array<string> = [] |
| | | |
| | | const vueBaseConfig = { |
| | | template: { |
| | | compilerOptions: { |
| | | isCustomElement: (id) => [tag].includes(id), |
| | | }, |
| | | }, |
| | | } |
| | | let buildWidgets: null | Record<string, any> = null |
| | | if (isCustom) { |
| | | try { |
| | | const isHasBuild = existsSync('.build.local') |
| | | if (isHasBuild) { |
| | | const fileContent = readFileSync('.build.local').toString('utf8') |
| | | if (fileContent) { |
| | | buildWidgets = fileContent.split('\n').filter((v) => v) |
| | | } |
| | | } else { |
| | | throw new Error('请先创建 .build.local文件') |
| | | } |
| | | } catch (error) { |
| | | console.log(error) |
| | | } |
| | | } |
| | | |
| | | if (isSingleBuild) { |
| | | const widgetName = readFileSync(argvPath, { encoding: 'utf8' }) |
| | |
| | | if (nodeIndex) { |
| | | const widgetNameMap = require(path.resolve(process.cwd(), baseBuildFile)) |
| | | getWidgetNames = widgetNameMap[nodeIndex] |
| | | if (buildWidgets) { |
| | | getWidgetNames = getWidgetNames.filter((widgetName) => { |
| | | return buildWidgets.includes(widgetName) |
| | | }) |
| | | } |
| | | } |
| | | } |
| | | |
| | | const library: any = getWidgetNames.map((name) => { |
| | | return { |
| | | outDir: isWin ? 'C:/Program Files/CMS Editor/host/wwwroot/widgets' : 'dist', |
| | | outDir: 'dist', |
| | | target: 'ES2022', |
| | | mode: 'development', |
| | | rollupOptions: { |
| | | external: ['vue', 'sdk'], |
| | | external: ['vue', 'sdk', 'vxe-table'], |
| | | output: { |
| | | globals: { |
| | | vue: 'Vue', |
| | |
| | | }, |
| | | } |
| | | }) |
| | | |
| | | //@ts-ignore |
| | | export default defineConfig(async ({ mode }) => { |
| | | const env: any = loadEnv(mode, __dirname) |
| | | |
| | | return { |
| | | define: { |
| | | 'process.env.VITE_STATIC_URL': `"${env?.VITE_STATIC_URL || ''}"`, |
| | | 'process.env': process.env, |
| | | 'window.__BUILD_TIME__': `"${dayjs().format('YYYY-MM-DD HH:mm:ss')}"`, |
| | | }, |
| | |
| | | }, |
| | | }, |
| | | publicDir: false, |
| | | |
| | | plugins: [ |
| | | vueJsx(), |
| | | svgIcon({ |
| | | include: [slash(path.resolve('./src/assets/svg-icon/*.svg'))], |
| | | }), |
| | | VitePluginDevelopmentFilter({ tag, prodTag: 'information-prod' }), |
| | | |
| | | vueJsx(vueBaseConfig.template.compilerOptions), |
| | | vue({ |
| | | reactivityTransform: true, |
| | | ...vueBaseConfig, |
| | | // @ts-ignore |
| | | reactivityTransform: path.resolve(__dirname, 'src'), |
| | | }), |
| | | VueTypeImports(), |
| | | VitePluginWidgetProvider(), |
| | |
| | | }), |
| | | ], |
| | | }), |
| | | |
| | | optimizeLodashImports(), |
| | | vitePluginForArco({ |
| | | style: 'css', |
| | | }), |
| | | ], |
| | | esbuild: { |
| | | drop: mode !== 'development' ? ['debugger', 'console'] : [], |
| | | drop: mode !== 'development' ? ['debugger' ] : [], |
| | | }, |
| | | css: { |
| | | preprocessorOptions: { |
| | | scss: { |
| | | additionalData: `@use "@/assets/styles/element.scss" as *;`, |
| | | }, |
| | | less: { |
| | | modifyVars: { |
| | | 'arcoblue-6': '#f85959', |
| | | '--primary-6': '#5a84ff', |
| | | }, |
| | | javascriptEnabled: true, |
| | | }, |
| | | }, |
| | | }, |
| | | } |