Files
esengine/packages/math/rollup.config.cjs

123 lines
2.3 KiB
JavaScript
Raw Normal View History

2025-08-11 10:25:28 +08:00
const resolve = require('@rollup/plugin-node-resolve');
2025-08-10 16:00:02 +08:00
const commonjs = require('@rollup/plugin-commonjs');
const terser = require('@rollup/plugin-terser');
const dts = require('rollup-plugin-dts').default;
2025-08-11 10:25:28 +08:00
const { readFileSync } = require('fs');
2025-08-10 16:00:02 +08:00
2025-08-11 10:25:28 +08:00
const pkg = JSON.parse(readFileSync('./package.json', 'utf8'));
const banner = `/**
* @esengine/ecs-framework-math v${pkg.version}
2025-08-11 10:25:28 +08:00
* ECS框架2D数学库 - 提供向量矩阵几何形状和碰撞检测功能
*
* @author ${pkg.author}
* @license ${pkg.license}
*/`;
2025-08-10 16:00:02 +08:00
const external = Object.keys(pkg.dependencies || {}).concat(Object.keys(pkg.peerDependencies || {}));
2025-08-11 10:25:28 +08:00
const commonPlugins = [
resolve({
browser: true,
preferBuiltins: false
}),
commonjs({
include: /node_modules/
})
];
2025-08-10 16:00:02 +08:00
module.exports = [
2025-08-11 10:25:28 +08:00
// ES模块构建
2025-08-10 16:00:02 +08:00
{
2025-08-11 10:25:28 +08:00
input: 'bin/index.js',
2025-08-10 16:00:02 +08:00
output: {
2025-08-11 10:25:28 +08:00
file: 'dist/index.mjs',
format: 'es',
banner,
sourcemap: true,
exports: 'named'
2025-08-10 16:00:02 +08:00
},
plugins: [
2025-08-11 10:25:28 +08:00
...commonPlugins,
terser({
format: {
comments: /^!/
}
})
],
external,
treeshake: {
moduleSideEffects: false,
propertyReadSideEffects: false,
unknownGlobalSideEffects: false
}
2025-08-10 16:00:02 +08:00
},
2025-08-11 10:25:28 +08:00
// CommonJS构建
2025-08-10 16:00:02 +08:00
{
2025-08-11 10:25:28 +08:00
input: 'bin/index.js',
2025-08-10 16:00:02 +08:00
output: {
2025-08-11 10:25:28 +08:00
file: 'dist/index.cjs',
2025-08-10 16:00:02 +08:00
format: 'cjs',
2025-08-11 10:25:28 +08:00
banner,
2025-08-10 16:00:02 +08:00
sourcemap: true,
exports: 'named'
},
2025-08-11 10:25:28 +08:00
plugins: [
...commonPlugins,
terser({
format: {
comments: /^!/
}
})
],
2025-08-10 16:00:02 +08:00
external,
2025-08-11 10:25:28 +08:00
treeshake: {
moduleSideEffects: false
}
},
// UMD构建
{
input: 'bin/index.js',
output: {
file: 'dist/index.umd.js',
format: 'umd',
name: 'ECSMath',
banner,
sourcemap: true,
exports: 'named'
},
2025-08-10 16:00:02 +08:00
plugins: [
2025-08-11 10:25:28 +08:00
...commonPlugins,
terser({
format: {
comments: /^!/
}
})
],
external: [],
treeshake: {
moduleSideEffects: false
}
2025-08-10 16:00:02 +08:00
},
2025-08-11 10:25:28 +08:00
// 类型定义构建
2025-08-10 16:00:02 +08:00
{
input: 'bin/index.d.ts',
output: {
file: 'dist/index.d.ts',
2025-08-11 10:25:28 +08:00
format: 'es',
banner: `/**
* @esengine/ecs-framework-math v${pkg.version}
2025-08-11 10:25:28 +08:00
* TypeScript definitions
*/`
2025-08-10 16:00:02 +08:00
},
2025-08-11 10:25:28 +08:00
plugins: [
dts({
respectExternal: true
})
],
external: []
2025-08-10 16:00:02 +08:00
}
];