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(clerk-js): Bundle CSS into CJS and ESM bundles #4301

Merged
merged 1 commit into from
Oct 8, 2024

Conversation

dstaley
Copy link
Member

@dstaley dstaley commented Oct 8, 2024

Description

This PR updates the CJS and ESM builds of clerk-js to bundle imported CSS files instead of emitting a URL to the file. This is required since we don't have the capability to dynamically load anything on account of not knowing the public path (like we do in our browser bundles). This impacts consumers who directly consume the clerk.js and clerk.mjs bundles of clerk-js, which includes Chrome extensions (and possibly others).

Checklist

  • npm test runs as expected.
  • npm run build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Copy link

changeset-bot bot commented Oct 8, 2024

⚠️ No Changeset found

Latest commit: 2926b6d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

const clerkUICSSLoader = () => {
// This emits a module exporting the URL to the styles.css file.
// This emits a module exporting a URL to the styles.css file.
Copy link
Member Author

Choose a reason for hiding this comment

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

These could be one loader with a boolean argument for supportsChunks. I didn't have a strong opinion one way to the other, so happy to change this if anyone else has a stronger opinion!

* Used for production builds that combine all files into one single file (such as for Chrome Extensions).
* @type { () => (import('webpack').Configuration) }
* */
const commonForProdBundled = () => {
Copy link
Member Author

@dstaley dstaley Oct 8, 2024

Choose a reason for hiding this comment

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

We could also do something like commonForProd({ chunked: true }) and do everything within the commonForProd function.

@@ -283,13 +326,19 @@ const prodConfig = ({ mode }) => {
],
});

const clerkCjs = merge(clerkEsm, {
const clerkCjs = merge(entryForVariant(variants.clerk), common({ mode }), commonForProd(), commonForProdBundled(), {
Copy link
Member Author

Choose a reason for hiding this comment

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

I removed the merge(clerkEsm portion because the experimental ESM output was confusing Webpack. It was emitting references to import.meta.url within the CJS output, which caused ATTW to complain.

@dstaley dstaley merged commit 29258d0 into brk.feat/render-ui-in-clerk-js Oct 8, 2024
4 checks passed
@dstaley dstaley deleted the ds.fix/bundle-css branch October 8, 2024 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants