Skip to content

Commit ac0fd39

Browse files
committed
[CSS Modules] Update our React/Preact tests to fit css-loader v7 default options, notify Vue users about the new behaviour and the solution
1 parent 8286aa1 commit ac0fd39

File tree

5 files changed

+48
-9
lines changed

5 files changed

+48
-9
lines changed

CHANGELOG.md

+31
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,37 @@ pnpm install webpack-dev-server --save-dev
9393

9494
* #1319 Drop support of css-loader ^6, add support for css-loader ^7.1 (@Kocal)
9595

96+
Since [`css-loader` 7.0.0](https://github.com/webpack-contrib/css-loader/blob/master/CHANGELOG.md#700-2024-04-04),
97+
styles imports became named by default.
98+
It means you should update your code from:
99+
```js
100+
import style from "./style.css";
101+
102+
console.log(style.myClass);
103+
```
104+
to:
105+
```js
106+
import * as style from "./style.css";
107+
108+
console.log(style.myClass);
109+
```
110+
111+
There is also a possibility to keep the previous behavior by configuring the `css-loader`'s `modules` option:
112+
```js
113+
config.configureCssLoader(options => {
114+
if (options.modules) {
115+
options.modules.namedExport = false;
116+
options.modules.exportLocalsConvention = 'as-is';
117+
}
118+
});
119+
```
120+
121+
> [!IMPORTANT]
122+
> If you use CSS Modules inside `.vue` files,
123+
> until https://github.com/vuejs/vue-loader/pull/1909 is merged and released, you will need to restore the previous
124+
> behavior by configuring Encore with the code above.
125+
126+
96127
## 4.7.0
97128

98129
### Features

fixtures/preact-css-modules/components/App.jsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import './styles.css';
33
import './styles.less';
44
import './styles.scss';
55
import './styles.stylus';
6-
import stylesCss from './styles.module.css?module';
7-
import stylesLess from './styles.module.less?module';
8-
import stylesScss from './styles.module.scss?module';
9-
import stylesStylus from './styles.module.stylus?module';
6+
import * as stylesCss from './styles.module.css?module';
7+
import * as stylesLess from './styles.module.less?module';
8+
import * as stylesScss from './styles.module.scss?module';
9+
import * as stylesStylus from './styles.module.stylus?module';
1010

1111
export default function App() {
1212
return <div className={`red large justified lowercase ${stylesCss.italic} ${stylesLess.underline} ${stylesScss.bold} ${stylesStylus.rtl}`}></div>

fixtures/react-css-modules/components/App.jsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import './styles.css';
22
import './styles.less';
33
import './styles.scss';
44
import './styles.stylus';
5-
import stylesCss from './styles.module.css?module';
6-
import stylesLess from './styles.module.less?module';
7-
import stylesScss from './styles.module.scss?module';
8-
import stylesStylus from './styles.module.stylus?module';
5+
import * as stylesCss from './styles.module.css?module';
6+
import * as stylesLess from './styles.module.less?module';
7+
import * as stylesScss from './styles.module.scss?module';
8+
import * as stylesStylus from './styles.module.stylus?module';
99

1010
export default function App() {
1111
return <div className={`red large justified lowercase ${stylesCss.italic} ${stylesLess.underline} ${stylesScss.bold} ${stylesStylus.rtl}`}></div>

fixtures/vuejs-jsx/components/Hello.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import styles from './Hello.css?module';
1+
import * as styles from './Hello.css?module';
22

33
export default {
44
name: 'hello',

test/functional.js

+8
Original file line numberDiff line numberDiff line change
@@ -1645,6 +1645,14 @@ module.exports = {
16451645
config.enableLessLoader();
16461646
config.enableStylusLoader();
16471647
config.configureCssLoader(options => {
1648+
// Until https://github.com/vuejs/vue-loader/pull/1909 is merged,
1649+
// Vue users should configure the css-loader modules
1650+
// to keep the previous default behavior from css-loader v6
1651+
if (options.modules) {
1652+
options.modules.namedExport = false;
1653+
options.modules.exportLocalsConvention = 'as-is';
1654+
}
1655+
16481656
// Remove hashes from local ident names
16491657
// since they are not always the same.
16501658
if (options.modules) {

0 commit comments

Comments
 (0)