diff --git a/package-lock.json b/package-lock.json index 10953803..79929bca 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11514,7 +11514,7 @@ }, "packages/core": { "name": "@esengine/ecs-framework", - "version": "2.1.30", + "version": "2.1.31", "license": "MIT", "devDependencies": { "@rollup/plugin-commonjs": "^28.0.3", @@ -11533,7 +11533,7 @@ }, "packages/math": { "name": "@esengine/ecs-framework-math", - "version": "1.0.2", + "version": "1.0.3", "license": "MIT", "devDependencies": { "@rollup/plugin-commonjs": "^28.0.3", @@ -11552,7 +11552,7 @@ }, "packages/network": { "name": "@esengine/ecs-framework-network", - "version": "1.0.1", + "version": "1.0.2", "license": "MIT", "dependencies": { "isomorphic-ws": "^5.0.0", diff --git a/package.json b/package.json index d2e391b3..c46720c9 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,8 @@ "test:ci": "lerna run test:ci", "prepare:publish": "npm run build:npm && node scripts/pre-publish-check.cjs", "sync:versions": "node scripts/sync-versions.cjs", - "publish:all": "npm run prepare:publish && lerna publish", + "publish:all": "npm run prepare:publish && npm run publish:all:dist", + "publish:all:dist": "npm run publish:core && npm run publish:math && npm run publish:network", "publish:core": "cd packages/core && npm run publish:npm", "publish:core:patch": "cd packages/core && npm run publish:patch", "publish:math": "cd packages/math && npm run publish:npm", diff --git a/packages/core/build-rollup.cjs b/packages/core/build-rollup.cjs index a10378da..6905b8ac 100644 --- a/packages/core/build-rollup.cjs +++ b/packages/core/build-rollup.cjs @@ -46,6 +46,7 @@ function generatePackageJson() { description: sourcePackage.description, main: 'index.cjs', module: 'index.mjs', + unpkg: 'index.umd.js', types: 'index.d.ts', exports: { '.': { @@ -59,6 +60,8 @@ function generatePackageJson() { 'index.mjs.map', 'index.cjs', 'index.cjs.map', + 'index.umd.js', + 'index.umd.js.map', 'index.d.ts', 'README.md', 'LICENSE', @@ -110,7 +113,7 @@ function copyFiles() { function showBuildResults() { const distDir = './dist'; - const files = ['index.mjs', 'index.cjs', 'index.d.ts']; + const files = ['index.mjs', 'index.cjs', 'index.umd.js', 'index.d.ts']; console.log('\n📊 构建结果:'); files.forEach(file => { diff --git a/packages/core/package.json b/packages/core/package.json index 30948dd9..f8ceff0f 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@esengine/ecs-framework", - "version": "2.1.30", + "version": "2.1.31", "description": "用于Laya、Cocos Creator等JavaScript游戏引擎的高性能ECS框架", "type": "module", "main": "bin/index.js", diff --git a/packages/core/rollup.config.cjs b/packages/core/rollup.config.cjs index 665214bc..a32a945b 100644 --- a/packages/core/rollup.config.cjs +++ b/packages/core/rollup.config.cjs @@ -76,6 +76,31 @@ module.exports = [ moduleSideEffects: false } }, + + // UMD构建 - 用于CDN和浏览器直接使用 + { + input: 'bin/index.js', + output: { + file: 'dist/index.umd.js', + format: 'umd', + name: 'ECS', + banner, + sourcemap: true, + exports: 'named' + }, + plugins: [ + ...commonPlugins, + terser({ + format: { + comments: /^!/ + } + }) + ], + external: [], + treeshake: { + moduleSideEffects: false + } + }, // 类型定义构建 { diff --git a/packages/math/build-rollup.cjs b/packages/math/build-rollup.cjs index 41baa0bc..743072a0 100644 --- a/packages/math/build-rollup.cjs +++ b/packages/math/build-rollup.cjs @@ -1,48 +1,125 @@ -const { execSync } = require('child_process'); const fs = require('fs'); const path = require('path'); +const { execSync } = require('child_process'); -console.log('开始构建 @esengine/ecs-framework-math...'); +console.log('🚀 使用 Rollup 构建 @esengine/ecs-framework-math npm包...'); -try { - // 检查bin目录是否存在 - if (!fs.existsSync('bin')) { - console.error('错误: bin目录不存在,请先运行 npm run build'); - process.exit(1); - } +async function main() { + try { + // 清理旧的dist目录 + if (fs.existsSync('./dist')) { + console.log('🧹 清理旧的构建文件...'); + execSync('rimraf ./dist', { stdio: 'inherit' }); + } - // 创建dist目录 - if (!fs.existsSync('dist')) { - fs.mkdirSync('dist'); - } + // 执行Rollup构建 + console.log('📦 执行 Rollup 构建...'); + execSync('rollup -c rollup.config.cjs', { stdio: 'inherit' }); - // 运行rollup构建 - execSync('npx rollup -c rollup.config.cjs', { stdio: 'inherit' }); + // 生成package.json + console.log('📋 生成 package.json...'); + generatePackageJson(); - // 复制package.json到dist - const pkg = require('./package.json'); - const distPkg = { - ...pkg, - main: 'index.cjs.js', - module: 'index.esm.js', - types: 'index.d.ts', - scripts: undefined, - devDependencies: undefined - }; + // 复制其他文件 + console.log('📁 复制必要文件...'); + copyFiles(); - fs.writeFileSync( - path.join('dist', 'package.json'), - JSON.stringify(distPkg, null, 2) - ); + // 输出构建结果 + showBuildResults(); - // 复制README(如果存在) - if (fs.existsSync('README.md')) { - fs.copyFileSync('README.md', path.join('dist', 'README.md')); - } + console.log('✅ 构建完成!'); + console.log('\n🚀 发布命令:'); + console.log('cd dist && npm publish'); - console.log('✓ @esengine/ecs-framework-math 构建完成'); + } catch (error) { + console.error('❌ 构建失败:', error.message); + process.exit(1); + } +} -} catch (error) { - console.error('构建失败:', error.message); - process.exit(1); -} \ No newline at end of file +function generatePackageJson() { + const sourcePackage = JSON.parse(fs.readFileSync('./package.json', 'utf8')); + + const distPackage = { + name: sourcePackage.name, + version: sourcePackage.version, + description: sourcePackage.description, + main: 'index.cjs', + module: 'index.mjs', + unpkg: 'index.umd.js', + types: 'index.d.ts', + exports: { + '.': { + import: './index.mjs', + require: './index.cjs', + types: './index.d.ts' + } + }, + files: [ + 'index.mjs', + 'index.mjs.map', + 'index.cjs', + 'index.cjs.map', + 'index.umd.js', + 'index.umd.js.map', + 'index.d.ts', + 'README.md', + 'LICENSE' + ], + keywords: [ + 'ecs', + 'math', + '2d', + 'vector', + 'matrix', + 'geometry', + 'collision', + 'game-engine', + 'typescript', + 'rollup' + ], + author: sourcePackage.author, + license: sourcePackage.license, + repository: sourcePackage.repository, + bugs: sourcePackage.bugs, + homepage: sourcePackage.homepage, + engines: { + node: '>=16.0.0' + }, + sideEffects: false + }; + + fs.writeFileSync('./dist/package.json', JSON.stringify(distPackage, null, 2)); +} + +function copyFiles() { + const filesToCopy = [ + { src: './README.md', dest: './dist/README.md' }, + { src: './LICENSE', dest: './dist/LICENSE' } + ]; + + filesToCopy.forEach(({ src, dest }) => { + if (fs.existsSync(src)) { + fs.copyFileSync(src, dest); + console.log(` ✓ 复制: ${path.basename(dest)}`); + } else { + console.log(` ⚠️ 文件不存在: ${src}`); + } + }); +} + +function showBuildResults() { + const distDir = './dist'; + const files = ['index.mjs', 'index.cjs', 'index.umd.js', 'index.d.ts']; + + console.log('\n📊 构建结果:'); + files.forEach(file => { + const filePath = path.join(distDir, file); + if (fs.existsSync(filePath)) { + const size = fs.statSync(filePath).size; + console.log(` ${file}: ${(size / 1024).toFixed(1)}KB`); + } + }); +} + +main().catch(console.error); \ No newline at end of file diff --git a/packages/math/package.json b/packages/math/package.json index 5277d240..726f6002 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -1,6 +1,6 @@ { "name": "@esengine/ecs-framework-math", - "version": "1.0.2", + "version": "1.0.3", "description": "ECS框架2D数学库 - 提供向量、矩阵、几何形状和碰撞检测功能", "type": "module", "main": "bin/index.js", diff --git a/packages/math/rollup.config.cjs b/packages/math/rollup.config.cjs index e71a7ab7..18cc2583 100644 --- a/packages/math/rollup.config.cjs +++ b/packages/math/rollup.config.cjs @@ -1,52 +1,123 @@ -const { nodeResolve } = require('@rollup/plugin-node-resolve'); +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 = require('./package.json'); +const pkg = JSON.parse(readFileSync('./package.json', 'utf8')); + +const banner = `/** + * @esengine/ecs-framework-math v${pkg.version} + * ECS框架2D数学库 - 提供向量、矩阵、几何形状和碰撞检测功能 + * + * @author ${pkg.author} + * @license ${pkg.license} + */`; -const input = 'bin/index.js'; const external = Object.keys(pkg.dependencies || {}).concat(Object.keys(pkg.peerDependencies || {})); +const commonPlugins = [ + resolve({ + browser: true, + preferBuiltins: false + }), + commonjs({ + include: /node_modules/ + }) +]; + module.exports = [ - // ES Module build + // ES模块构建 { - input, + input: 'bin/index.js', output: { - file: 'dist/index.esm.js', - format: 'esm', - sourcemap: true - }, - external, - plugins: [ - nodeResolve(), - commonjs(), - terser() - ] - }, - // CommonJS build - { - input, - output: { - file: 'dist/index.cjs.js', - format: 'cjs', + file: 'dist/index.mjs', + format: 'es', + banner, sourcemap: true, exports: 'named' }, - external, plugins: [ - nodeResolve(), - commonjs(), - terser() - ] + ...commonPlugins, + terser({ + format: { + comments: /^!/ + } + }) + ], + external, + treeshake: { + moduleSideEffects: false, + propertyReadSideEffects: false, + unknownGlobalSideEffects: false + } }, - // TypeScript declarations + + // CommonJS构建 + { + input: 'bin/index.js', + output: { + file: 'dist/index.cjs', + format: 'cjs', + banner, + sourcemap: true, + exports: 'named' + }, + plugins: [ + ...commonPlugins, + terser({ + format: { + comments: /^!/ + } + }) + ], + external, + treeshake: { + moduleSideEffects: false + } + }, + + // UMD构建 + { + input: 'bin/index.js', + output: { + file: 'dist/index.umd.js', + format: 'umd', + name: 'ECSMath', + banner, + sourcemap: true, + exports: 'named' + }, + plugins: [ + ...commonPlugins, + terser({ + format: { + comments: /^!/ + } + }) + ], + external: [], + treeshake: { + moduleSideEffects: false + } + }, + + // 类型定义构建 { input: 'bin/index.d.ts', output: { file: 'dist/index.d.ts', - format: 'esm' + format: 'es', + banner: `/** + * @esengine/ecs-framework-math v${pkg.version} + * TypeScript definitions + */` }, - plugins: [dts()] + plugins: [ + dts({ + respectExternal: true + }) + ], + external: [] } ]; \ No newline at end of file diff --git a/packages/network/build-rollup.cjs b/packages/network/build-rollup.cjs index 4aa7b21c..155aeed8 100644 --- a/packages/network/build-rollup.cjs +++ b/packages/network/build-rollup.cjs @@ -46,6 +46,7 @@ function generatePackageJson() { description: sourcePackage.description, main: 'index.cjs', module: 'index.mjs', + unpkg: 'index.umd.js', types: 'index.d.ts', exports: { '.': { @@ -59,6 +60,8 @@ function generatePackageJson() { 'index.mjs.map', 'index.cjs', 'index.cjs.map', + 'index.umd.js', + 'index.umd.js.map', 'index.d.ts', 'README.md', 'LICENSE' @@ -67,7 +70,7 @@ function generatePackageJson() { 'ecs', 'networking', 'frame-sync', - 'protobuf', + 'tsrpc', 'serialization', 'multiplayer', 'game-engine', @@ -77,14 +80,13 @@ function generatePackageJson() { author: sourcePackage.author, license: sourcePackage.license, repository: sourcePackage.repository, + bugs: sourcePackage.bugs, + homepage: sourcePackage.homepage, engines: { node: '>=16.0.0' }, - dependencies: { - '@esengine/ecs-framework': sourcePackage.peerDependencies['@esengine/ecs-framework'], - 'protobufjs': sourcePackage.dependencies.protobufjs, - 'reflect-metadata': sourcePackage.dependencies['reflect-metadata'] - }, + dependencies: sourcePackage.dependencies, + peerDependencies: sourcePackage.peerDependencies, sideEffects: false }; @@ -109,7 +111,7 @@ function copyFiles() { function showBuildResults() { const distDir = './dist'; - const files = ['index.mjs', 'index.cjs', 'index.d.ts']; + const files = ['index.mjs', 'index.cjs', 'index.umd.js', 'index.d.ts']; console.log('\n📊 构建结果:'); files.forEach(file => { diff --git a/packages/network/package.json b/packages/network/package.json index 24087121..c1b8cf26 100644 --- a/packages/network/package.json +++ b/packages/network/package.json @@ -1,6 +1,6 @@ { "name": "@esengine/ecs-framework-network", - "version": "1.0.1", + "version": "1.0.2", "description": "ECS框架网络插件 - 提供TSRPC网络通信、帧同步和快照功能", "type": "module", "main": "bin/index.js", diff --git a/packages/network/rollup.config.cjs b/packages/network/rollup.config.cjs index 25ef9d20..4a618d10 100644 --- a/packages/network/rollup.config.cjs +++ b/packages/network/rollup.config.cjs @@ -82,6 +82,36 @@ module.exports = [ } }, + // UMD构建 - 用于CDN和浏览器直接使用 + { + input: 'bin/index.js', + output: { + file: 'dist/index.umd.js', + format: 'umd', + name: 'ECSNetwork', + banner, + sourcemap: true, + exports: 'named', + globals: { + '@esengine/ecs-framework': 'ECS', + 'protobufjs': 'protobuf', + 'reflect-metadata': 'Reflect' + } + }, + plugins: [ + ...commonPlugins, + terser({ + format: { + comments: /^!/ + } + }) + ], + external: ['@esengine/ecs-framework', 'protobufjs', 'reflect-metadata'], + treeshake: { + moduleSideEffects: false + } + }, + // 类型定义构建 { input: 'bin/index.d.ts',