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

Fix tsup configuration for vanilla Webpack 4 without babel-loader #5322

Merged
merged 4 commits into from
Oct 9, 2024

Conversation

compulim
Copy link
Contributor

@compulim compulim commented Oct 9, 2024

Changelog Entry

Fixed

  • Improved importability in vanilla Webpack 4 without babel-loader, by @compulim, in PR #5322

Description

There are some limitations on vanilla Webpack 4 without babel-loader:

  • Cannot load ESM and it imports CJS (a.k.a. "ESM -> CJS")
    • We need noExternal: 'globalize' only for ESM
      • globalize is CJS-only, we bundle it inside Web Chat so it don't do "ESM -> CJS"
    • We don't need bundling for CJS as it won't do "ESM -> CJS"
  • Webpack 4 does not understand ES2020, need to target ES2019
    • It does not understand ?? operator
  • No named imports, requires barrel file for interoperability
    • We made some mistakes in our barrel file
    • Barrel files need to point to .js, otherwise, Webpack 4 may point to .mjs which will require Babel

Also, in tsup, it disabled code splitting for CJS as esbuild does not support it. We are using experimental flag to re-enable it.

If you want code splitting for cjs output format as well, try using --splitting flag which is an experimental feature to get rid of the limitation in esbuild.

Design

Specific Changes

  • Fix barrel files and force it to CJS
  • Target ES2019 for CJS, Chrome 100/Safari 15 for ESM
  • Bundle globalize only in ESM but not CJS
    • Only needed in ESM as globalize is CJS only and it would cross the ESM -> CJS boundary
  • Force code splitting for CJS
    • We have multiple entrypoints: botframework-webchat-[api|component]/[decorator|internal]
    • React context requires same instance, i.e. code splitting is required
  • I have added tests and executed them locally
  • I have updated CHANGELOG.md
  • I have updated documentation

Review Checklist

This section is for contributors to review your work.

  • 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)

@compulim compulim changed the title Fix tsup for Webpack 4 Fix tsup configuration for Webpack 4 Oct 9, 2024
@compulim compulim changed the title Fix tsup configuration for Webpack 4 Fix tsup configuration for vanilla Webpack 4 without babel-loader Oct 9, 2024
@compulim compulim marked this pull request as ready for review October 9, 2024 11:11
Copy link
Collaborator

@OEvgeny OEvgeny left a comment

Choose a reason for hiding this comment

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

Looks good. Who the hell is using Webpack 4 without any preloader in 2024? It kind of kills progress of the past ~4 years in web development.

@OEvgeny OEvgeny enabled auto-merge (squash) October 9, 2024 17:54
@OEvgeny OEvgeny merged commit 63e5cb0 into main Oct 9, 2024
27 checks passed
@OEvgeny OEvgeny deleted the fix-tsup-for-webpack4 branch October 9, 2024 18:00
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