Skip to content

Conversation

@s-meiser
Copy link

Summary

  • add new TypeScript sources under src-ts/ and emit ESM, CJS, and .d.ts outputs
  • wire npm scripts and tsconfig files for the modern builds plus a lightweight terser-based UMD bundle
  • retain the original Gulp pipeline and dist/accordion.min.js so existing consumers remain unaffected
  • refresh project docs to explain the new build flow and the optional legacy regeneration step

Motivation

  • Tree-shaking through the ESM build lets modern bundlers include only what is used, reducing payload size
  • CJS + types give Node/TypeScript users first-class support without external wrappers
  • Zero migration for direct <script> / CDN users because the legacy UMD bundle and Gulp workflow stay intact

Build Outputs

  • ESM: esm/
  • CJS: cjs/
  • Types: dist-types/
  • UMD (legacy + terser rebuild): dist/accordion.min.js

package.json exposes the builds like this:

{
  "main": "dist/accordion.min.js",
  "module": "esm/index.js",
  "types": "dist-types/index.d.ts",
  "exports": {
    ".": {
      "types": "./dist-types/index.d.ts",
      "import": "./esm/index.js",
      "require": "./cjs/index.js",
      "default": "./dist/accordion.min.js"
    },
    "./dist/accordion.min.css": "./dist/accordion.min.css"
  }
}

Testing / Verification

  1. Build modern outputs: npm run build
  2. Regenerate the legacy bundle: npm run build:legacy
  3. (Optional) produce the terser UMD bundle after building TS outputs: npm run build:bundle
  4. Manual smoke tests (optional):
    • node -e "import('./esm/index.js').then(m => console.log(Object.keys(m)))"
    • node -e "console.log(Object.keys(require('./cjs/index.js')))"

Size (legacy UMD, minified)

before after delta
7 144 B 7 110 B −34 B (~0.48%)

Docs

  • Updated build instructions to cover modern outputs, legacy regeneration, and optional UMD rebuild

Backward Compatibility

  • No breaking changes expected: the legacy UMD bundle remains the default export path
  • Modern bundlers can opt into the ESM/CJS builds transparently through exports

Notes / Follow-ups

  • Consider documenting minimum supported Node / TypeScript versions in the README
  • Future CI could run npm run build, npm run build:legacy, and a minimal import smoke test for both module formats

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant