Skip to content

Commit

Permalink
[CSS Modules] Update our React/Preact tests to fit css-loader v7 defa…
Browse files Browse the repository at this point in the history
…ult options, notify Vue users about the new behaviour and the solution
  • Loading branch information
Kocal committed Sep 20, 2024
1 parent 8286aa1 commit ac0fd39
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 9 deletions.
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,37 @@ pnpm install webpack-dev-server --save-dev

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

Since [`css-loader` 7.0.0](https://github.com/webpack-contrib/css-loader/blob/master/CHANGELOG.md#700-2024-04-04),
styles imports became named by default.
It means you should update your code from:
```js
import style from "./style.css";

console.log(style.myClass);
```
to:
```js
import * as style from "./style.css";

console.log(style.myClass);
```

There is also a possibility to keep the previous behavior by configuring the `css-loader`'s `modules` option:
```js
config.configureCssLoader(options => {
if (options.modules) {
options.modules.namedExport = false;
options.modules.exportLocalsConvention = 'as-is';
}
});
```

> [!IMPORTANT]
> If you use CSS Modules inside `.vue` files,
> until https://github.com/vuejs/vue-loader/pull/1909 is merged and released, you will need to restore the previous
> behavior by configuring Encore with the code above.

## 4.7.0

### Features
Expand Down
8 changes: 4 additions & 4 deletions fixtures/preact-css-modules/components/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import './styles.css';
import './styles.less';
import './styles.scss';
import './styles.stylus';
import stylesCss from './styles.module.css?module';
import stylesLess from './styles.module.less?module';
import stylesScss from './styles.module.scss?module';
import stylesStylus from './styles.module.stylus?module';
import * as stylesCss from './styles.module.css?module';
import * as stylesLess from './styles.module.less?module';
import * as stylesScss from './styles.module.scss?module';
import * as stylesStylus from './styles.module.stylus?module';

export default function App() {
return <div className={`red large justified lowercase ${stylesCss.italic} ${stylesLess.underline} ${stylesScss.bold} ${stylesStylus.rtl}`}></div>
Expand Down
8 changes: 4 additions & 4 deletions fixtures/react-css-modules/components/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import './styles.css';
import './styles.less';
import './styles.scss';
import './styles.stylus';
import stylesCss from './styles.module.css?module';
import stylesLess from './styles.module.less?module';
import stylesScss from './styles.module.scss?module';
import stylesStylus from './styles.module.stylus?module';
import * as stylesCss from './styles.module.css?module';
import * as stylesLess from './styles.module.less?module';
import * as stylesScss from './styles.module.scss?module';
import * as stylesStylus from './styles.module.stylus?module';

export default function App() {
return <div className={`red large justified lowercase ${stylesCss.italic} ${stylesLess.underline} ${stylesScss.bold} ${stylesStylus.rtl}`}></div>
Expand Down
2 changes: 1 addition & 1 deletion fixtures/vuejs-jsx/components/Hello.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import styles from './Hello.css?module';
import * as styles from './Hello.css?module';

export default {
name: 'hello',
Expand Down
8 changes: 8 additions & 0 deletions test/functional.js
Original file line number Diff line number Diff line change
Expand Up @@ -1645,6 +1645,14 @@ module.exports = {
config.enableLessLoader();
config.enableStylusLoader();
config.configureCssLoader(options => {
// Until https://github.com/vuejs/vue-loader/pull/1909 is merged,
// Vue users should configure the css-loader modules
// to keep the previous default behavior from css-loader v6
if (options.modules) {
options.modules.namedExport = false;
options.modules.exportLocalsConvention = 'as-is';
}

// Remove hashes from local ident names
// since they are not always the same.
if (options.modules) {
Expand Down

0 comments on commit ac0fd39

Please sign in to comment.