2024-05-23 10:10:18 +00:00
|
|
|
// import PreprocessorDirectives from 'unplugin-preprocessor-directives/vite';
|
2024-04-14 16:09:08 +00:00
|
|
|
import obfuscator from 'rollup-plugin-obfuscator';
|
|
|
|
import cp from 'vite-plugin-cp';
|
|
|
|
import { UserConfig, defineConfig } from 'vite';
|
|
|
|
import { resolve } from 'path';
|
|
|
|
import { PluginOption, Plugin } from 'vite';
|
|
|
|
import nodeResolve from '@rollup/plugin-node-resolve';
|
|
|
|
import { builtinModules } from 'module';
|
|
|
|
import fs from 'node:fs';
|
2024-06-18 14:49:06 +00:00
|
|
|
import babel from 'vite-plugin-babel';
|
2024-08-08 12:42:09 +00:00
|
|
|
//依赖排除
|
2024-07-24 02:44:55 +00:00
|
|
|
const external = ['silk-wasm', 'ws', 'express', 'fluent-ffmpeg', 'log4js', 'qrcode-terminal'];
|
2024-04-14 16:09:08 +00:00
|
|
|
const nodeModules = [...builtinModules, builtinModules.map(m => `node:${m}`)].flat();
|
2024-08-08 12:42:09 +00:00
|
|
|
|
2024-04-14 16:09:08 +00:00
|
|
|
function genCpModule(module: string) {
|
2024-04-23 10:38:13 +00:00
|
|
|
return { src: `./node_modules/${module}`, dest: `dist/node_modules/${module}`, flatten: false };
|
2024-04-14 16:09:08 +00:00
|
|
|
}
|
2024-08-08 12:42:09 +00:00
|
|
|
|
2024-05-03 13:00:17 +00:00
|
|
|
let startScripts: string[] | undefined = undefined;
|
2024-05-03 13:34:16 +00:00
|
|
|
if (process.env.NAPCAT_BUILDSYS == 'linux') {
|
|
|
|
if (process.env.NAPCAT_BUILDARCH == 'x64') {
|
2024-05-03 13:22:16 +00:00
|
|
|
}
|
2024-05-03 13:00:17 +00:00
|
|
|
startScripts = ['./script/napcat.sh'];
|
2024-05-03 13:34:16 +00:00
|
|
|
} else if (process.env.NAPCAT_BUILDSYS == 'win32') {
|
|
|
|
if (process.env.NAPCAT_BUILDARCH == 'x64') {
|
2024-05-03 13:22:16 +00:00
|
|
|
}
|
2024-08-11 09:43:59 +00:00
|
|
|
startScripts = ['./script/BootWay05.ps1', './script/dbghelp.dll'];
|
2024-05-03 13:22:16 +00:00
|
|
|
} else {
|
2024-08-11 09:43:59 +00:00
|
|
|
startScripts = ['./script/BootWay05.ps1', './script/dbghelp.dll'];
|
2024-05-03 13:00:17 +00:00
|
|
|
}
|
2024-08-10 09:45:17 +00:00
|
|
|
const FrameworkBaseConfigPlugin: PluginOption[] = [
|
2024-08-08 12:57:10 +00:00
|
|
|
// PreprocessorDirectives(),
|
|
|
|
babel({
|
|
|
|
filter: /.*\.(ts|js)$/,
|
|
|
|
babelConfig: {
|
|
|
|
babelrc: false,
|
|
|
|
configFile: false,
|
|
|
|
presets: ["@babel/preset-typescript"],
|
|
|
|
plugins: [
|
|
|
|
//'2018-09', decoratorsBeforeExport: true
|
|
|
|
['@babel/plugin-proposal-decorators', { legacy: true }],
|
|
|
|
'@babel/plugin-proposal-class-properties',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
cp({
|
|
|
|
targets: [
|
|
|
|
{ src: './manifest.json', dest: 'dist' },
|
2024-08-10 13:56:55 +00:00
|
|
|
{ src: './src/external/napcat.json', dest: 'dist/config/' },
|
2024-08-11 05:48:26 +00:00
|
|
|
{ src: './static/', dest: 'dist/static/', flatten: false },
|
2024-08-10 13:58:37 +00:00
|
|
|
{ src: './src/external/onebot11.json', dest: 'dist/config/' },
|
2024-08-10 09:50:23 +00:00
|
|
|
{ src: './src/framework/liteloader.cjs', dest: 'dist' },
|
2024-08-10 09:45:17 +00:00
|
|
|
{ src: './src/framework/napcat.cjs', dest: 'dist' },
|
|
|
|
{ src: './src/framework/preload.cjs', dest: 'dist' },
|
|
|
|
{ src: './src/framework/renderer.js', dest: 'dist' },
|
2024-08-08 13:12:23 +00:00
|
|
|
{ src: './package.json', dest: 'dist' },
|
2024-08-08 12:57:10 +00:00
|
|
|
{ src: './logo.png', dest: 'dist' },
|
2024-08-08 13:12:23 +00:00
|
|
|
//...external.map(genCpModule)
|
2024-08-08 12:57:10 +00:00
|
|
|
]
|
|
|
|
}),
|
|
|
|
nodeResolve(),
|
|
|
|
];
|
|
|
|
const ShellBaseConfigPlugin: PluginOption[] = [
|
2024-05-03 13:22:16 +00:00
|
|
|
// PreprocessorDirectives(),
|
2024-06-18 14:49:06 +00:00
|
|
|
babel({
|
2024-06-18 15:23:19 +00:00
|
|
|
filter: /.*\.(ts|js)$/,
|
2024-06-18 14:49:06 +00:00
|
|
|
babelConfig: {
|
|
|
|
babelrc: false,
|
|
|
|
configFile: false,
|
|
|
|
presets: ["@babel/preset-typescript"],
|
|
|
|
plugins: [
|
|
|
|
//'2018-09', decoratorsBeforeExport: true
|
|
|
|
['@babel/plugin-proposal-decorators', { legacy: true }],
|
|
|
|
'@babel/plugin-proposal-class-properties',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
}),
|
2024-05-03 13:22:16 +00:00
|
|
|
cp({
|
|
|
|
targets: [
|
|
|
|
// ...external.map(genCpModule),
|
2024-08-08 12:42:09 +00:00
|
|
|
// { src: './src/napcat.json', dest: 'dist/config/' },
|
2024-08-11 09:43:59 +00:00
|
|
|
{ src: './static/', dest: 'dist/static/', flatten: false },
|
2024-08-08 12:42:09 +00:00
|
|
|
// { src: './src/onebot11/onebot11.json', dest: 'dist/config/' },
|
2024-08-10 13:56:55 +00:00
|
|
|
{ src: './src/external/napcat.json', dest: 'dist/config/' },
|
2024-08-10 13:58:37 +00:00
|
|
|
{ src: './src/external/onebot11.json', dest: 'dist/config/' },
|
2024-08-10 13:56:55 +00:00
|
|
|
{ src: './package.json', dest: 'dist' },
|
2024-08-08 12:42:09 +00:00
|
|
|
// { src: './README.md', dest: 'dist' },
|
|
|
|
// { src: './logo.png', dest: 'dist/logs' },
|
2024-08-11 09:43:59 +00:00
|
|
|
...(startScripts.map((startScript) => {
|
|
|
|
return { src: startScript, dest: 'dist' };
|
|
|
|
})),
|
2024-05-03 13:22:16 +00:00
|
|
|
]
|
|
|
|
}),
|
|
|
|
nodeResolve(),
|
|
|
|
];
|
2024-05-03 13:03:13 +00:00
|
|
|
|
2024-08-08 12:42:09 +00:00
|
|
|
const ShellBaseConfig = () => defineConfig({
|
|
|
|
resolve: {
|
|
|
|
conditions: ['node', 'default'],
|
|
|
|
alias: {
|
2024-08-08 12:43:36 +00:00
|
|
|
'@/core': resolve(__dirname, './src/core'),
|
2024-08-08 12:42:09 +00:00
|
|
|
'@': 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({
|
2024-04-14 16:09:08 +00:00
|
|
|
resolve: {
|
|
|
|
conditions: ['node', 'default'],
|
|
|
|
alias: {
|
2024-08-08 12:43:36 +00:00
|
|
|
'@/core': resolve(__dirname, './src/core'),
|
2024-04-14 16:09:08 +00:00
|
|
|
'@': resolve(__dirname, './src'),
|
|
|
|
'./lib-cov/fluent-ffmpeg': './lib/fluent-ffmpeg',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
build: {
|
2024-08-08 12:42:09 +00:00
|
|
|
sourcemap: false,
|
2024-04-14 16:09:08 +00:00
|
|
|
target: 'esnext',
|
2024-04-28 13:02:56 +00:00
|
|
|
minify: false,
|
2024-04-14 16:09:08 +00:00
|
|
|
lib: {
|
2024-08-10 09:45:17 +00:00
|
|
|
entry: "src/framework/napcat.ts",
|
2024-05-22 11:58:45 +00:00
|
|
|
formats: ['es'],
|
|
|
|
fileName: () => 'napcat.mjs',
|
2024-04-14 16:09:08 +00:00
|
|
|
},
|
|
|
|
rollupOptions: {
|
|
|
|
external: [...nodeModules, ...external]
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2024-04-23 10:38:13 +00:00
|
|
|
export default defineConfig(({ mode }): UserConfig => {
|
2024-08-08 11:26:27 +00:00
|
|
|
if (mode === 'shell') {
|
2024-04-14 16:09:08 +00:00
|
|
|
return {
|
2024-08-08 12:42:09 +00:00
|
|
|
...ShellBaseConfig(),
|
2024-08-08 12:57:10 +00:00
|
|
|
plugins: [...ShellBaseConfigPlugin]
|
2024-04-14 16:09:08 +00:00
|
|
|
};
|
|
|
|
} else {
|
|
|
|
return {
|
2024-08-10 09:45:17 +00:00
|
|
|
...FrameworkBaseConfig(),
|
|
|
|
plugins: [...FrameworkBaseConfigPlugin],
|
2024-04-14 16:09:08 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|