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

CSS modules keeps the original className mapping #612

Closed
pastelsky opened this issue Sep 16, 2017 · 1 comment
Closed

CSS modules keeps the original className mapping #612

pastelsky opened this issue Sep 16, 2017 · 1 comment

Comments

@pastelsky
Copy link

pastelsky commented Sep 16, 2017

Consider this CSS modules setup with extract text plugin-

Section.css

.section__heading {
  /* styles */
}

Section.js

import styles from './section.css'

function Section() {
  return <section> <h1 className={ styles.section__heading }> H1 </h1> </section>
}

Current behavior

Currently, css-loader goes through the normal process of creating a module out of the import, and even storing the original name mapping. The resulting JS file looks similar to

build.js (current)

//  Module
"5mvV":
  (function(module, exports) {
    module.exports={
      "section__heading":"_3a24I",
    };
  }),
// Usage
className={ __webpack_require__("5mvV").default.section__heading }
// ...

Expected behaviour

Ideally, css loader should just inline the "hashed" classname wherever its being used.
One of the benefits of hashing classnames is reduction in file sizes in comparison with techniques such as BEM. But if the original mapping is stored, this purpose is defeated.

build.js (expected)

// The classname is inlined
className="_3a24I"
@michael-ciniawsky
Copy link
Member

michael-ciniawsky commented Jan 8, 2018

CSS Modules will be removed for 'css-loader soon and will become a separate plugin (postcss-loader`)

The css-loader will be able to export locals as Named ESM Exports in v1.0.0

export const className = 'Ä3825t';
// ... CSS Modules
//... Custom Exports (from other postcss-plugins)

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

No branches or pull requests

2 participants