headplane/server/vite.config.ts

77 lines
1.7 KiB
TypeScript
Raw Normal View History

import { createRequire } from 'node:module';
2025-01-01 15:06:22 +05:30
import { defineConfig } from 'vite';
2025-01-17 08:33:22 +00:00
import tsconfigPaths from 'vite-tsconfig-paths';
import { devDependencies } from '../package.json';
2025-01-01 15:06:22 +05:30
const prefix = process.env.__INTERNAL_PREFIX || '/admin';
if (prefix.endsWith('/')) {
throw new Error('Prefix must not end with a slash');
}
const require = createRequire(import.meta.url);
2025-01-17 08:33:22 +00:00
export default defineConfig({
define: {
__hp_prefix: JSON.stringify(prefix),
},
resolve: {
preserveSymlinks: true,
alias: {
buffer: 'node:buffer',
crypto: 'node:crypto',
events: 'node:events',
fs: 'node:fs',
net: 'node:net',
http: 'node:http',
https: 'node:https',
os: 'node:os',
path: 'node:path',
2025-01-17 08:33:22 +00:00
stream: 'node:stream',
tls: 'node:tls',
url: 'node:url',
zlib: 'node:zlib',
ws: require.resolve('ws'),
2025-01-01 15:06:22 +05:30
},
2025-01-17 08:33:22 +00:00
},
plugins: [tsconfigPaths()],
build: {
minify: false,
target: 'node18',
// lib: {
// entry: 'server/entry.ts',
// formats: ['es'],
// },
2025-01-17 08:33:22 +00:00
rollupOptions: {
input: 'server/entry.ts',
2025-01-17 08:33:22 +00:00
treeshake: {
moduleSideEffects: false,
2025-01-01 15:06:22 +05:30
},
2025-01-17 08:33:22 +00:00
output: {
entryFileNames: 'server.js',
dir: 'build/headplane',
banner: '#!/usr/bin/env node\n',
},
// We are selecting a list of dependencies we want to include
// We are only including our production dependencies
2025-01-17 08:33:22 +00:00
external: (id) => {
if (id.startsWith('node:')) {
2025-01-17 08:33:22 +00:00
return true;
}
if (id === 'ws') {
return true;
}
const match = id.match(/node_modules\/([^/]+)/);
if (match) {
return true;
// const dep = match[1];
// if ((devDependencies as Record<string, string>)[dep]) {
// return true;
// }
}
},
2025-01-01 15:06:22 +05:30
},
},
});