Skip to content

feat: export class names as an ESM #336

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

Closed
wants to merge 1 commit into from

Conversation

que-etc
Copy link

@que-etc que-etc commented Jan 9, 2019

This PR contains a:

  • bugfix
  • new feature
  • code refactor
  • test update
  • typo fix
  • metadata update

Motivation / Use-Case

Closes #43.

Consuming class names as an ESM with named exports makes Webpack to include them as separate bindings, which in turn, allows minifires to mangle them or inline those class names.

It all leads to a reduced size of a bundle, which, in case of our app, was ~30Kib of a minified code.

Breaking Changes

This a backward-compatible change due to an interoperability between ESM and CJS implemented in Webpack.

Additional Info

Tests weren't updated because none of them assert exports of JS modules. Unfortunately, I've no idea how it can be tested given the existing cases.

@jsf-clabot
Copy link

jsf-clabot commented Jan 9, 2019

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

It is breaking change, we can do this only in next major release, anyway thanks for the PR

@que-etc
Copy link
Author

que-etc commented Jan 9, 2019

@evilebottnawi from an application's perspective or that it might break integration with other plugins?

@alexander-akait
Copy link
Member

@que-etc

from an application's perspective

Also we need first implement this in css-loader and style-loader

Object.keys(locals).forEach((exportName) => {
const className = locals[exportName];

resultSource += `\nexport const ${exportName} = '${className}';`;
Copy link

Choose a reason for hiding this comment

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

Will this work with class names that have hyphens in them? Especially if css-loader isn't specifically configured to convert the locals into camelCase or something.

@alexander-akait
Copy link
Member

Done in master

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.

Export locals as ES2015 Modules
4 participants