27aea728df
- exports `RestApiClient` from 'twenty-client-sdk/rest';` - documents the rest client
80 lines
2.0 KiB
TypeScript
80 lines
2.0 KiB
TypeScript
import path from 'path';
|
|
import { defineConfig } from 'vite';
|
|
import tsconfigPaths from 'vite-tsconfig-paths';
|
|
import packageJson from './package.json';
|
|
|
|
const entries = [
|
|
'src/core/index.ts',
|
|
'src/metadata/index.ts',
|
|
'src/rest/index.ts',
|
|
'src/generate/index.ts',
|
|
];
|
|
|
|
const entryFileNames = (chunk: any, extension: 'cjs' | 'mjs') => {
|
|
if (!chunk.isEntry) {
|
|
throw new Error(
|
|
`Should never occur, encountered a non entry chunk ${chunk.facadeModuleId}`,
|
|
);
|
|
}
|
|
|
|
const splitFaceModuleId = chunk.facadeModuleId?.split('/');
|
|
if (splitFaceModuleId === undefined) {
|
|
throw new Error(
|
|
`Should never occur, splitFaceModuleId is undefined ${chunk.facadeModuleId}`,
|
|
);
|
|
}
|
|
|
|
const moduleDirectory = splitFaceModuleId[splitFaceModuleId?.length - 2];
|
|
if (moduleDirectory === 'src') {
|
|
return `${chunk.name}.${extension}`;
|
|
}
|
|
return `${moduleDirectory}.${extension}`;
|
|
};
|
|
|
|
export default defineConfig(() => {
|
|
return {
|
|
root: __dirname,
|
|
cacheDir: '../../node_modules/.vite/packages/twenty-client-sdk',
|
|
resolve: {
|
|
alias: {
|
|
'@/': path.resolve(__dirname, 'src') + '/',
|
|
},
|
|
},
|
|
plugins: [
|
|
tsconfigPaths({
|
|
root: __dirname,
|
|
}),
|
|
],
|
|
build: {
|
|
emptyOutDir: false,
|
|
outDir: 'dist',
|
|
lib: { entry: entries, name: 'twenty-client-sdk' },
|
|
rollupOptions: {
|
|
external: [
|
|
...Object.keys((packageJson as any).dependencies || {}),
|
|
...Object.keys((packageJson as any).devDependencies || {}).filter(
|
|
(dep: string) => dep !== 'twenty-shared',
|
|
),
|
|
'node:fs/promises',
|
|
'node:fs',
|
|
'node:path',
|
|
],
|
|
output: [
|
|
{
|
|
format: 'es',
|
|
entryFileNames: (chunk) => entryFileNames(chunk, 'mjs'),
|
|
},
|
|
{
|
|
format: 'cjs',
|
|
interop: 'auto',
|
|
esModule: true,
|
|
exports: 'named',
|
|
entryFileNames: (chunk) => entryFileNames(chunk, 'cjs'),
|
|
},
|
|
],
|
|
},
|
|
},
|
|
logLevel: 'warn',
|
|
};
|
|
});
|