Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build: add entry points without top level side-effects #5329

Merged
merged 12 commits into from
Oct 23, 2024

Conversation

OEvgeny
Copy link
Collaborator

@OEvgeny OEvgeny commented Oct 22, 2024

Fixes #

Changelog Entry

Changed

  • Excluded side effects from module entry points to prevent global scope modification, in PR #5329, by @OEvgeny

Description

This PR improves the bundle architecture by migrating from Webpack to tsup and restructuring entry points to eliminate top-level side effects.

Design

The solution implements a cleaner separation between bundle and module code:

  1. /module/exports*.ts - Pure ES/CJS modules without side effects

    • Export Web Chat API surface
    • Maintain module-level encapsulation
    • Enable tree-shaking optimizations
  2. /bundle/index*.ts - Bundle entry points with controlled side effects

    • Handle global window.WebChat registration
    • Manage version metadata
    • Import and expose module exports

This approach:

  • Separates concerns between module API and bundle initialization
  • Improves predictability of side effects
  • Makes the codebase more maintainable
  • Enables better tree-shaking in downstream applications

Specific Changes

  • Migrated build system from Webpack to tsup
  • Restructured bundle package layout:
    • Added src/module/exports.ts, exports-es5.ts, exports-minimal.ts
    • Added src/bundle/index.ts, index-es5.ts, index-minimal.ts
    • Moved polyfill.ts to src/bundle
  • Updated package.json:
    • Removed Webpack-related dependencies
    • Updated build scripts to use tsup
  • Improved type definitions
  • Added React resolution through isomorphic-react

-

  • I have added tests and executed them locally
  • I have updated CHANGELOG.md
  • I have updated documentation

Review Checklist

  • Accessibility reviewed (tab order, content readability, alt text, color contrast)
  • Browser and platform compatibilities reviewed
  • CSS styles reviewed (minimal rules, no z-index)
  • Documents reviewed (docs, samples, live demo)
  • Internationalization reviewed (strings, unit formatting)
  • package.json and package-lock.json reviewed
  • Security reviewed (no data URIs, check for nonce leak)
  • Tests reviewed (coverage, legitimacy)

@OEvgeny OEvgeny marked this pull request as ready for review October 22, 2024 22:20
Copy link
Contributor

@compulim compulim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that we don't need to export global in a way that we dupe export as modules.

@OEvgeny OEvgeny merged commit 7bceaaf into main Oct 23, 2024
27 checks passed
@OEvgeny OEvgeny deleted the feature/clean-bundle branch October 23, 2024 19:23
@compulim compulim mentioned this pull request Oct 24, 2024
11 tasks
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.

2 participants