chore: init project
This commit is contained in:
51
internal/vite-config/src/config/library.ts
Normal file
51
internal/vite-config/src/config/library.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import type { UserConfig } from 'vite';
|
||||
|
||||
import { readPackageJSON } from '@vben/node-utils';
|
||||
import { defineConfig, mergeConfig } from 'vite';
|
||||
|
||||
import { getLibraryConditionPlugins } from '../plugins';
|
||||
import { getCommonConfig } from './common';
|
||||
|
||||
import type { DefineLibraryOptions } from '../typing';
|
||||
|
||||
function defineLibraryConfig(options: DefineLibraryOptions = {}) {
|
||||
return defineConfig(async ({ command, mode }) => {
|
||||
const root = process.cwd();
|
||||
const { library = {}, vite = {} } = options;
|
||||
const isBuild = command === 'build';
|
||||
|
||||
const plugins = await getLibraryConditionPlugins({
|
||||
dts: false,
|
||||
injectLibCss: true,
|
||||
isBuild,
|
||||
mode,
|
||||
...library,
|
||||
});
|
||||
|
||||
const { dependencies = {}, peerDependencies = {} } =
|
||||
await readPackageJSON(root);
|
||||
|
||||
const external = [
|
||||
...Object.keys(dependencies),
|
||||
...Object.keys(peerDependencies),
|
||||
];
|
||||
const packageConfig: UserConfig = {
|
||||
build: {
|
||||
lib: {
|
||||
entry: 'src/index.ts',
|
||||
fileName: () => 'index.mjs',
|
||||
formats: ['es'],
|
||||
},
|
||||
rollupOptions: {
|
||||
external,
|
||||
},
|
||||
},
|
||||
plugins,
|
||||
};
|
||||
const commonConfig = await getCommonConfig();
|
||||
const mergedConfig = mergeConfig(commonConfig, packageConfig);
|
||||
return mergeConfig(mergedConfig, vite);
|
||||
});
|
||||
}
|
||||
|
||||
export { defineLibraryConfig };
|
Reference in New Issue
Block a user