import resolve from '@rollup/plugin-node-resolve'; import commonjs from '@rollup/plugin-commonjs'; import json from '@rollup/plugin-json'; import path from 'path'; import esbuild from 'rollup-plugin-esbuild'; import alias from '@rollup/plugin-alias'; import replace from '@rollup/plugin-replace'; import pkgs from './package.json' with { type: 'json' }; import dts from 'rollup-plugin-dts'; const isDev = process.env.NODE_ENV === 'development'; const version = pkgs.version|| '1.0.0'; const external = [ /@kevisual\/router(\/.*)?/, //, // 路由 /@kevisual\/use-config(\/.*)?/, // 'sequelize', // 数据库 orm 'ioredis', // redis 'socket.io', // socket.io 'minio', // minio 'pm2', 'pg', // pg 'pino', // pino 'pino-pretty', // pino-pretty '@msgpack/msgpack', // msgpack ] /** * @type {import('rollup').RollupOptions} */ const config = { input: './src/lib.ts', output: { dir: './dist', entryFileNames: 'lib.mjs', chunkFileNames: '[name]-[hash].mjs', format: 'esm', }, plugins: [ replace({ preventAssignment: true, // 防止意外赋值 DEV_SERVER: JSON.stringify(isDev), // 替换 process.env.NODE_ENV VERSION: JSON.stringify(version), // 替换版本号 }), alias({ // only esbuild needs to be configured entries: [ { find: '@', replacement: path.resolve('src') }, // 配置 @ 为 src 目录 ], }), resolve({ preferBuiltins: true, // 强制优先使用内置模块 }), commonjs(), esbuild({ target: 'node22', // 目标为 Node.js 14 minify: false, // 启用代码压缩 tsconfig: 'tsconfig.json', }), json(), ], external: external, }; const configCjs = { input: './src/lib.ts', output: { dir: './dist', entryFileNames: 'lib.cjs', chunkFileNames: '[name]-[hash].cjs', format: 'cjs', }, plugins: [ replace({ preventAssignment: true, // 防止意外赋值 DEV_SERVER: JSON.stringify(isDev), // 替换 process.env.NODE_ENV VERSION: JSON.stringify(version), // 替换版本号 }), alias({ // only esbuild needs to be configured entries: [ { find: '@', replacement: path.resolve('src') }, // 配置 @ 为 src 目录 ], }), resolve({ preferBuiltins: true, // 强制优先使用内置模块 }), commonjs(), esbuild({ target: 'node22', // 目标为 Node.js 14 minify: false, // 启用代码压缩 tsconfig: 'tsconfig.json', }), json(), ], external: external, }; const dtsConfig = { input: './src/lib.ts', output: { dir: './dist', entryFileNames: 'lib.d.ts', format: 'esm', }, plugins: [ dts(), ], }; const systemConfig = [ { input: './src/system.ts', output: { dir: './dist', entryFileNames: 'system.mjs', chunkFileNames: '[name]-[hash].mjs', format: 'esm', }, plugins: [ replace({ preventAssignment: true, // 防止意外赋值 DEV_SERVER: JSON.stringify(isDev), // 替换 process.env.NODE_ENV VERSION: JSON.stringify(version), // 替换版本号 }), alias({ entries: [ { find: '@', replacement: path.resolve('src') }, // 配置 @ 为 src 目录 ], }), resolve({ preferBuiltins: true, // 强制优先使用内置模块 }), commonjs(), esbuild({ target: 'node22', // 目标为 Node.js 14 minify: false, // 启用代码压缩 tsconfig: 'tsconfig.json', }), json(), ], external: [...external, ], }, { input: './src/system.ts', output: { dir: './dist', entryFileNames: 'system.d.ts', format: 'esm', }, plugins: [ dts(), ], }, ] export default [config, dtsConfig, ...systemConfig];