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' }; const isDev = process.env.NODE_ENV === 'development'; const version = pkgs.version|| '1.0.0'; /** * @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), // 替换 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: ['isolated-vm'], }; export default config;