NapCatQQ/vite.config.ts

116 lines
3.9 KiB
TypeScript
Raw Normal View History

2024-04-14 16:09:08 +00:00
import cp from 'vite-plugin-cp';
import { defineConfig, PluginOption, UserConfig } from 'vite';
2024-04-14 16:09:08 +00:00
import { resolve } from 'path';
import nodeResolve from '@rollup/plugin-node-resolve';
import { builtinModules } from 'module';
//依赖排除
2024-11-14 07:43:11 +00:00
const external = ['silk-wasm', 'ws', 'express', 'qrcode-terminal', 'fluent-ffmpeg'];
2024-04-14 16:09:08 +00:00
const nodeModules = [...builtinModules, builtinModules.map(m => `node:${m}`)].flat();
function genCpModule(module: string) {
return { src: `./node_modules/${module}`, dest: `dist/node_modules/${module}`, flatten: false };
}
let startScripts: string[] | undefined = undefined;
2024-05-03 13:34:16 +00:00
if (process.env.NAPCAT_BUILDSYS == 'linux') {
2024-09-17 03:08:47 +00:00
startScripts = [];
2024-05-03 13:34:16 +00:00
} else if (process.env.NAPCAT_BUILDSYS == 'win32') {
2024-09-17 03:08:47 +00:00
startScripts = ['./script/KillQQ.bat'];
2024-05-03 13:22:16 +00:00
} else {
2024-09-17 03:08:47 +00:00
startScripts = ['./script/KillQQ.bat'];
2024-05-03 13:00:17 +00:00
}
2024-08-10 09:45:17 +00:00
const FrameworkBaseConfigPlugin: PluginOption[] = [
cp({
targets: [
{ src: './manifest.json', dest: 'dist' },
2024-08-11 17:21:14 +00:00
{ src: './src/core/external/napcat.json', dest: 'dist/config/' },
2024-11-05 02:14:00 +00:00
{ src: './src/native/packet', dest: 'dist/moehoo', flatten: false },
{ src: './static/', dest: 'dist/static/', flatten: false },
{ src: './src/onebot/config/onebot11.json', dest: 'dist/config/' },
{ src: './src/framework/liteloader.cjs', dest: 'dist' },
{ src: './src/framework/napcat.cjs', dest: 'dist' },
{ src: './src/framework/preload.cjs', dest: 'dist' },
{ src: './src/framework/renderer.js', dest: 'dist' },
{ src: './package.json', dest: 'dist' },
{ src: './logo.png', dest: 'dist' },
],
}),
nodeResolve(),
];
const ShellBaseConfigPlugin: PluginOption[] = [
cp({
targets: [
2024-11-05 02:14:00 +00:00
{ src: './src/native/packet', dest: 'dist/moehoo', flatten: false },
{ src: './static/', dest: 'dist/static/', flatten: false },
{ src: './src/core/external/napcat.json', dest: 'dist/config/' },
2024-08-28 07:27:38 +00:00
{ src: './src/onebot/config/onebot11.json', dest: 'dist/config/' },
{ src: './package.json', dest: 'dist' },
2024-09-04 15:12:38 +00:00
{ src: './launcher/', dest: 'dist', flatten: true },
...(startScripts.map((startScript) => {
return { src: startScript, dest: 'dist' };
})),
],
}),
nodeResolve(),
2024-05-03 13:22:16 +00:00
];
2024-05-03 13:03:13 +00:00
const ShellBaseConfig = () => defineConfig({
resolve: {
conditions: ['node', 'default'],
alias: {
'@/core': resolve(__dirname, './src/core'),
'@': resolve(__dirname, './src'),
'./lib-cov/fluent-ffmpeg': './lib/fluent-ffmpeg',
},
},
build: {
sourcemap: false,
target: 'esnext',
minify: false,
lib: {
entry: 'src/shell/napcat.ts',
formats: ['es'],
fileName: () => 'napcat.mjs',
},
rollupOptions: {
external: [...nodeModules, ...external],
},
},
});
2024-04-14 16:09:08 +00:00
2024-08-10 09:45:17 +00:00
const FrameworkBaseConfig = () => defineConfig({
resolve: {
conditions: ['node', 'default'],
alias: {
'@/core': resolve(__dirname, './src/core'),
'@': resolve(__dirname, './src'),
'./lib-cov/fluent-ffmpeg': './lib/fluent-ffmpeg',
},
2024-04-14 16:09:08 +00:00
},
build: {
sourcemap: false,
target: 'esnext',
minify: false,
lib: {
entry: 'src/framework/napcat.ts',
formats: ['es'],
fileName: () => 'napcat.mjs',
},
rollupOptions: {
external: [...nodeModules, ...external],
},
2024-04-14 16:09:08 +00:00
},
});
2024-04-23 10:38:13 +00:00
export default defineConfig(({ mode }): UserConfig => {
if (mode === 'shell') {
return {
...ShellBaseConfig(),
plugins: [...ShellBaseConfigPlugin],
};
} else {
return {
...FrameworkBaseConfig(),
plugins: [...FrameworkBaseConfigPlugin],
};
}
2024-04-14 16:09:08 +00:00
});