代码拉取完成,页面将自动刷新
// import PreprocessorDirectives from 'unplugin-preprocessor-directives/vite';
import cp from 'vite-plugin-cp';
import { defineConfig, PluginOption, UserConfig } from 'vite';
import { resolve } from 'path';
import nodeResolve from '@rollup/plugin-node-resolve';
import { builtinModules } from 'module';
import babel from 'vite-plugin-babel';
//依赖排除
const external = ['silk-wasm', 'ws', 'express', 'fluent-ffmpeg', 'log4js', 'qrcode-terminal'];
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;
if (process.env.NAPCAT_BUILDSYS == 'linux') {
if (process.env.NAPCAT_BUILDARCH == 'x64') {
}
startScripts = [];
} else if (process.env.NAPCAT_BUILDSYS == 'win32') {
if (process.env.NAPCAT_BUILDARCH == 'x64') {
}
startScripts = ['./script/KillQQ.bat'];
} else {
startScripts = ['./script/KillQQ.bat'];
}
const FrameworkBaseConfigPlugin: PluginOption[] = [
// 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' },
{ src: './src/core/external/napcat.json', dest: 'dist/config/' },
{ 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' },
//...external.map(genCpModule)
],
}),
nodeResolve(),
];
const ShellBaseConfigPlugin: PluginOption[] = [
// 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: [
// ...external.map(genCpModule),
// { src: './src/napcat.json', dest: 'dist/config/' },
{ src: './static/', dest: 'dist/static/', flatten: false },
// { src: './src/onebot11/onebot11.json', dest: 'dist/config/' },
{ src: './src/core/external/napcat.json', dest: 'dist/config/' },
{ src: './src/onebot/config/onebot11.json', dest: 'dist/config/' },
{ src: './package.json', dest: 'dist' },
{ src: './launcher/', dest: 'dist', flatten: true },
// { src: './README.md', dest: 'dist' },
// { src: './logo.png', dest: 'dist/logs' },
...(startScripts.map((startScript) => {
return { src: startScript, dest: 'dist' };
})),
],
}),
nodeResolve(),
];
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],
},
},
});
const FrameworkBaseConfig = () => 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/framework/napcat.ts',
formats: ['es'],
fileName: () => 'napcat.mjs',
},
rollupOptions: {
external: [...nodeModules, ...external],
},
},
});
export default defineConfig(({ mode }): UserConfig => {
if (mode === 'shell') {
return {
...ShellBaseConfig(),
plugins: [...ShellBaseConfigPlugin],
};
} else {
return {
...FrameworkBaseConfig(),
plugins: [...FrameworkBaseConfigPlugin],
};
}
});
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。