From 7ad4e13e8e9d00da5104d32c5fc07d9bc128b1f3 Mon Sep 17 00:00:00 2001 From: umbraci Date: Wed, 22 Oct 2025 14:26:11 +0800 Subject: [PATCH 1/2] feat: add multiple build output formats (ES/CJS/UMD) - Configure Rollup to generate three output formats: - ES Module (es/) for modern bundlers with tree-shaking - CommonJS (lib/) for require/legacy toolchains - UMD (dist/) for direct script usage with global variables - Update package.json exports to support all formats - Add build outputs to .gitignore - Support both unpkg and jsdelivr CDN usage --- .config/rollup.config.js | 149 +++++++++++++++++++++++++-------------- .gitignore | 8 +++ package.json | 20 +++--- 3 files changed, 117 insertions(+), 60 deletions(-) diff --git a/.config/rollup.config.js b/.config/rollup.config.js index fa1d3471..308aa2ef 100644 --- a/.config/rollup.config.js +++ b/.config/rollup.config.js @@ -1,59 +1,111 @@ import cleanup from 'rollup-plugin-cleanup'; import terser from '@rollup/plugin-terser'; -export default [ - { - input: 'src/jsmind.js', - output: { +const banner = + '/**\n* @license BSD-3-Clause\n* @copyright 2014-2025 hizzgdev@163.com\n*\n* Project Home:\n* https://github.com/hizzgdev/jsmind/\n*/'; + +const cleanupPlugin = cleanup({ + comments: 'none', +}); + +const terserPlugin = terser({ + output: { + comments: 'all', + }, +}); + +// Main library configuration +const mainConfig = { + input: 'src/jsmind.js', + output: [ + // ES Module - for modern bundlers with tree-shaking support + { + file: 'es/jsmind.js', + format: 'es', + banner, + sourcemap: true, + }, + // CommonJS - for require/legacy toolchains + { + file: 'lib/jsmind.js', + format: 'cjs', + banner, + sourcemap: true, + exports: 'auto', + }, + // UMD - for direct