77 lines
2.8 KiB
JavaScript
77 lines
2.8 KiB
JavaScript
import typescript from '@rollup/plugin-typescript';
|
||
import resolve from '@rollup/plugin-node-resolve';
|
||
import commonjs from '@rollup/plugin-commonjs';
|
||
// import copy from 'rollup-plugin-copy';
|
||
// import { dts } from 'rollup-plugin-dts';
|
||
import json from '@rollup/plugin-json';
|
||
import path from 'path';
|
||
import alias from '@rollup/plugin-alias';
|
||
import esbuild from 'rollup-plugin-esbuild';
|
||
import replace from '@rollup/plugin-replace';
|
||
|
||
const isDev = process.env.NODE_ENV === 'development';
|
||
// 是否内联应用,内联应用不会启动服务,只会导出 App 实例,从package.json中获取
|
||
const exportApp = true;
|
||
console.log('isDev================:', isDev);
|
||
/**
|
||
* @type {import('rollup').RollupOptions}
|
||
*/
|
||
const config = {
|
||
input: './src/index.ts',
|
||
output: {
|
||
dir: './dist',
|
||
entryFileNames: 'app.mjs',
|
||
chunkFileNames: '[name]-[hash].mjs',
|
||
format: 'esm',
|
||
},
|
||
plugins: [
|
||
replace({
|
||
preventAssignment: true, // // 避免替换时发生意外赋值
|
||
DEV_SERVER: JSON.stringify(isDev), // DEV_SERVE
|
||
EXPORT_APP: JSON.stringify(exportApp), // 是否内联应用
|
||
EXPORT_PORT: JSON.stringify(3006), // 导出端口
|
||
}),
|
||
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, // 强制优先使用内置模块
|
||
}),
|
||
commonjs(),
|
||
esbuild({
|
||
target: 'node22', // 目标为 Node.js 14
|
||
minify: false, // 启用代码压缩
|
||
tsconfig: 'tsconfig.json',
|
||
}),
|
||
// typescript({
|
||
// declaration: false,
|
||
// }),
|
||
json(),
|
||
],
|
||
external: ['sequelize', '@kevisual/router', 'ioredis', 'socket.io', 'minio', 'pm2'],
|
||
};
|
||
export default config;
|