81 lines
2.9 KiB
JavaScript
81 lines
2.9 KiB
JavaScript
// rollup.config.js
|
|
|
|
import typescript from '@rollup/plugin-typescript';
|
|
import resolve from '@rollup/plugin-node-resolve';
|
|
import commonjs from '@rollup/plugin-commonjs';
|
|
import json from '@rollup/plugin-json';
|
|
import path from 'path';
|
|
import fs from 'fs';
|
|
|
|
import esbuild from 'rollup-plugin-esbuild';
|
|
import alias from '@rollup/plugin-alias';
|
|
import replace from '@rollup/plugin-replace';
|
|
|
|
const pkgs = JSON.parse(fs.readFileSync('./package.json', 'utf-8'));
|
|
/**
|
|
* @type {import('rollup').RollupOptions}
|
|
*/
|
|
const config = {
|
|
input: 'src/index.ts', // TypeScript 入口文件
|
|
output: {
|
|
dir: 'dist',
|
|
entryFileNames: 'app.mjs',
|
|
chunkFileNames: '[name]-[hash].mjs',
|
|
format: 'esm', // 输出格式设置为 ES 模块
|
|
},
|
|
plugins: [
|
|
replace({
|
|
preventAssignment: true, // 防止意外赋值
|
|
VERSION: JSON.stringify(pkgs.version || '1.0.0'),
|
|
}),
|
|
alias({
|
|
// only esbuild needs to be configured
|
|
entries: [
|
|
{ find: '@', replacement: path.resolve('src') }, // 配置 @ 为 src 目录
|
|
{ find: 'http', replacement: 'node:http' },
|
|
{ find: 'https', replacement: 'node:https' },
|
|
{ find: 'fs', replacement: 'node:fs' },
|
|
{ find: 'path', replacement: 'node:path' },
|
|
{ find: 'crypto', replacement: 'node:crypto' },
|
|
{ find: 'zlib', replacement: 'node:zlib' },
|
|
{ find: 'stream', replacement: 'node:stream' },
|
|
{ find: 'net', replacement: 'node:net' },
|
|
{ find: 'tty', replacement: 'node:tty' },
|
|
{ find: 'tls', replacement: 'node:tls' },
|
|
{ find: 'buffer', replacement: 'node:buffer' },
|
|
{ find: 'timers', replacement: 'node:timers' },
|
|
// { find: 'string_decoder', replacement: 'node:string_decoder' },
|
|
{ find: 'dns', replacement: 'node:dns' },
|
|
{ find: 'domain', replacement: 'node:domain' },
|
|
{ find: 'os', replacement: 'node:os' },
|
|
{ find: 'events', replacement: 'node:events' },
|
|
{ find: 'url', replacement: 'node:url' },
|
|
{ find: 'assert', replacement: 'node:assert' },
|
|
{ find: 'util', replacement: 'node:util' },
|
|
],
|
|
}),
|
|
resolve({
|
|
preferBuiltins: true, // 强制优先使用内置模块
|
|
}), // 使用 @rollup/plugin-node-resolve 解析 node_modules 中的模块
|
|
commonjs({
|
|
// dynamicRequireTargets: ['node_modules/sqlite3/lib/*.js'],
|
|
}),
|
|
esbuild({
|
|
target: 'node22', // 目标为 Node.js 14
|
|
minify: false, // 启用代码压缩
|
|
tsconfig: 'tsconfig.json',
|
|
}),
|
|
json(),
|
|
// typescript({
|
|
// allowImportingTsExtensions: true,
|
|
// noEmit: true,
|
|
// // 不生成声明文件
|
|
// declaration: false,
|
|
// }), // 使用 @rollup/plugin-typescript 处理 TypeScript 文件
|
|
],
|
|
// 将 sqlite3 作为外部依赖
|
|
external: ['sqlite3', 'sequelize', 'vite', 'sequelize', '@kevisual/router', 'ioredis', 'socket.io', 'minio'],
|
|
};
|
|
|
|
export default [config];
|