78 lines
2.1 KiB
TypeScript
78 lines
2.1 KiB
TypeScript
import { existsSync, writeFileSync } from 'node:fs';
|
|
import { fileURLToPath } from 'node:url';
|
|
import vue from '@vitejs/plugin-vue';
|
|
import vueJsx from '@vitejs/plugin-vue-jsx';
|
|
import UnoCSS from 'unocss/vite';
|
|
import { defineConfig } from 'vite';
|
|
import dts from 'vite-plugin-dts';
|
|
|
|
// https://vitejs.dev/config/
|
|
export default defineConfig({
|
|
// define: {
|
|
// 'process.env': process.env,
|
|
// },
|
|
build: {
|
|
emptyOutDir: false,
|
|
lib: {
|
|
entry: fileURLToPath(new URL('src/index.ts', import.meta.url)),
|
|
formats: ['es'],
|
|
name: 'lowcode-create',
|
|
},
|
|
sourcemap: true,
|
|
rollupOptions: {
|
|
onwarn(warning, warn) {
|
|
// Suppress "is imported from external module but never used" warnings for Vue internals
|
|
if (warning.code === 'UNUSED_EXTERNAL_IMPORT' && warning.exporter === 'vue') {
|
|
return;
|
|
}
|
|
warn(warning);
|
|
},
|
|
external: ['vue', 'element-plus-cisdi', 'lodash-es', 'uuid'],
|
|
output: {
|
|
globals: {
|
|
'vue': 'Vue',
|
|
'element-plus-cisdi': 'ElementPlusCisdi',
|
|
'lodash-es': 'LodashEs',
|
|
'uuid': 'Uuid',
|
|
},
|
|
exports: 'named',
|
|
banner: `
|
|
/**
|
|
* Copyright ${new Date(Date.now()).getFullYear()} Cisdi
|
|
* @license MIT
|
|
**/
|
|
`,
|
|
entryFileNames: '[name].js',
|
|
chunkFileNames: '[name]-[hash].js',
|
|
assetFileNames: '[name].[ext]',
|
|
},
|
|
},
|
|
},
|
|
plugins: [
|
|
vue(),
|
|
vueJsx(),
|
|
UnoCSS(),
|
|
dts({
|
|
include: ['src/**/*'],
|
|
exclude: ['src/**/*.spec.ts', 'src/**/*.test.ts'],
|
|
copyDtsFiles: true,
|
|
entryRoot: 'src',
|
|
afterBuild() {
|
|
// vite-plugin-dts 不会为纯类型重导出模块生成 index.d.ts
|
|
// 这里手动创建缺失的 typings/index.d.ts
|
|
const typingsIndexPath = 'dist/typings/index.d.ts';
|
|
if (!existsSync(typingsIndexPath)) {
|
|
writeFileSync(typingsIndexPath, `export * from './BaseWidgetProps';
|
|
export * from './DesignerApiInterface';
|
|
export * from './DesignerConfig';
|
|
export * from './DetailRender';
|
|
export * from './FormApisType';
|
|
export * from './FormSchema';
|
|
export * from './RuntimeApi';
|
|
`);
|
|
}
|
|
},
|
|
}),
|
|
],
|
|
});
|