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

feat(css): allow to use default and named export #18271

Merged
merged 2 commits into from Apr 2, 2024

Conversation

alexander-akait
Copy link
Member

@alexander-akait alexander-akait commented Apr 2, 2024

What kind of change does this PR introduce?

feature - allow to use default and named export

The same as requested here - webpack-contrib/mini-css-extract-plugin#1084

/cc @ahabhgk What do you think about it?

The main idea - allow to easy migrate from default to named, by default it is disabled (because we use only named export), but if developers have a lot of code, it is not easy to migrate fast, so developer can disable named export and use both of them

Did you add tests for your changes?

Yes

Does this PR introduce a breaking change?

No

What needs to be documented once your changes are merged?

When named export is disabled for CSS modules you can get classes using (we redirect named export for better DX, it will allow to migrate from default export to named smoothly):

import * as styles from "./styles.css";
import styles1 from "./styles.css";
import { foo } from "./styles.css";

console.log(styles.default.foo);
console.log(styles.foo);
console.log(styles1.foo);
console.log(foo);

When namedExport: true, you can use only named export.

@webpack-bot
Copy link
Contributor

webpack-bot commented Apr 2, 2024

For maintainers only:

  • This needs to be documented (issue in webpack/webpack.js.org will be filed when merged)
  • This needs to be backported to webpack 4 (issue will be created when merged)

@ahabhgk
Copy link
Contributor

ahabhgk commented Apr 2, 2024

Good idea, looks good to me

@alexander-akait alexander-akait merged commit 3361a5e into main Apr 2, 2024
45 of 47 checks passed
@alexander-akait alexander-akait deleted the allow_to_use-default-and-named-export branch April 2, 2024 15:29
@webpack-bot
Copy link
Contributor

I've created an issue to document this in webpack/webpack.js.org.

@nyngwang
Copy link

nyngwang commented Apr 2, 2024

@alexander-akait Do we need to update any option from css-loader, e.g. the option modules.namedExport? Do we need to ensure it's set to true to work correctly?

@alexander-akait
Copy link
Member Author

alexander-akait commented Apr 2, 2024

@nyngwang Yeah, let's check it and add tests, anyway I want to make namedExport to true by default in css-loader in the next major release (we should start to migrate to the named export), just want to finish webpack-contrib/css-loader#1532 (will be glad with help) before make a major release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants