Files
esengine/packages/network-client/rollup.config.cjs

133 lines
2.5 KiB
JavaScript
Raw Normal View History

const resolve = require('@rollup/plugin-node-resolve');
const commonjs = require('@rollup/plugin-commonjs');
const terser = require('@rollup/plugin-terser');
const dts = require('rollup-plugin-dts').default;
const { readFileSync } = require('fs');
const pkg = JSON.parse(readFileSync('./package.json', 'utf8'));
const banner = `/**
* @esengine/network-client v${pkg.version}
* ECS网络层客户端实现
*
* @author ${pkg.author}
* @license ${pkg.license}
*/`;
// 外部依赖不打包进bundle
const external = [
'@esengine/ecs-framework',
'@esengine/network-shared',
'reflect-metadata'
];
const commonPlugins = [
resolve({
browser: true,
preferBuiltins: false
}),
commonjs({
include: /node_modules/
})
];
module.exports = [
// ES模块构建
{
input: 'bin/index.js',
output: {
2025-07-07 11:49:36 +08:00
file: 'dist/index.mjs',
format: 'es',
banner,
sourcemap: true,
exports: 'named'
},
plugins: [
...commonPlugins,
terser({
format: {
comments: /^!/
}
})
],
external,
treeshake: {
moduleSideEffects: false,
propertyReadSideEffects: false,
unknownGlobalSideEffects: false
}
},
2025-07-07 11:49:36 +08:00
// CommonJS构建
{
input: 'bin/index.js',
output: {
2025-07-07 11:49:36 +08:00
file: 'dist/index.cjs',
format: 'cjs',
banner,
sourcemap: true,
exports: 'named'
},
plugins: [
...commonPlugins,
terser({
format: {
comments: /^!/
}
})
],
external,
treeshake: {
moduleSideEffects: false
}
},
2025-08-12 09:39:07 +08:00
// UMD构建 - 用于浏览器直接使用
2025-08-11 10:25:28 +08:00
{
input: 'bin/index.js',
output: {
file: 'dist/index.umd.js',
format: 'umd',
2025-08-12 09:39:07 +08:00
name: 'ECSNetworkClient',
2025-08-11 10:25:28 +08:00
banner,
sourcemap: true,
exports: 'named',
globals: {
'@esengine/ecs-framework': 'ECS',
'@esengine/network-shared': 'ECSNetworkShared',
'reflect-metadata': 'Reflect'
2025-08-11 10:25:28 +08:00
}
},
plugins: [
...commonPlugins,
terser({
format: {
comments: /^!/
}
})
],
2025-08-12 09:39:07 +08:00
external,
2025-08-11 10:25:28 +08:00
treeshake: {
moduleSideEffects: false
}
},
// 类型定义构建
{
input: 'bin/index.d.ts',
output: {
file: 'dist/index.d.ts',
format: 'es',
banner: `/**
* @esengine/network-client v${pkg.version}
* TypeScript definitions
*/`
},
plugins: [
dts({
respectExternal: true
})
],
2025-08-12 09:39:07 +08:00
external
}
];