Skip to content

Commit 524aa92

Browse files
committed
feature #1319 Drop support of css-loader ^6, add support for css-loader ^7.1 (Kocal)
This PR was squashed before being merged into the main branch. Discussion ---------- Drop support of css-loader ^6, add support for css-loader ^7.1 Let's continue to upgrade major dependencies, see https://github.com/webpack-contrib/css-loader/blob/master/CHANGELOG.md#700-2024-04-04 for changelog Commits ------- ac0fd39 [CSS Modules] Update our React/Preact tests to fit css-loader v7 default options, notify Vue users about the new behaviour and the solution 8286aa1 Drop support of css-loader ^6, add support for css-loader ^7.1
2 parents 675d68d + ac0fd39 commit 524aa92

File tree

7 files changed

+55
-14
lines changed

7 files changed

+55
-14
lines changed

CHANGELOG.md

+33
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,39 @@ pnpm install webpack-dev-server --save-dev
9191

9292
* #1342 Replace [`assets-webpack-plugin`](https://github.com/ztoben/assets-webpack-plugin) dependency by an internal plugin, to generate `entrypoints.json` file (@Kocal)
9393

94+
* #1319 Drop support of css-loader ^6, add support for css-loader ^7.1 (@Kocal)
95+
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+
94127
## 4.7.0
95128

96129
### 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',

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"dependencies": {
3030
"@nuxt/friendly-errors-webpack-plugin": "^2.5.1",
3131
"babel-loader": "^9.1.3",
32-
"css-loader": "^6.7.0",
32+
"css-loader": "^7.1.0",
3333
"css-minimizer-webpack-plugin": "^7.0.0",
3434
"fastest-levenshtein": "^1.0.16",
3535
"mini-css-extract-plugin": "^2.6.0",

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) {

yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -2716,10 +2716,10 @@ css-declaration-sorter@^7.2.0:
27162716
resolved "https://registry.yarnpkg.com/css-declaration-sorter/-/css-declaration-sorter-7.2.0.tgz#6dec1c9523bc4a643e088aab8f09e67a54961024"
27172717
integrity sha512-h70rUM+3PNFuaBDTLe8wF/cdWu+dOZmb7pJt8Z2sedYbAcQVQV/tEchueg3GWxwqS0cxtbxmaHEdkNACqcvsow==
27182718

2719-
css-loader@^6.7.0:
2720-
version "6.11.0"
2721-
resolved "https://registry.yarnpkg.com/css-loader/-/css-loader-6.11.0.tgz#33bae3bf6363d0a7c2cf9031c96c744ff54d85ba"
2722-
integrity sha512-CTJ+AEQJjq5NzLga5pE39qdiSV56F8ywCIsqNIRF0r7BDgWsN25aazToqAFg7ZrtA/U016xudB3ffgweORxX7g==
2719+
css-loader@^7.1.0:
2720+
version "7.1.2"
2721+
resolved "https://registry.yarnpkg.com/css-loader/-/css-loader-7.1.2.tgz#64671541c6efe06b0e22e750503106bdd86880f8"
2722+
integrity sha512-6WvYYn7l/XEGN8Xu2vWFt9nVzrCn39vKyTEFf/ExEyoksJjjSZV/0/35XPlMbpnr6VGhZIUg5yJrL8tGfes/FA==
27232723
dependencies:
27242724
icss-utils "^5.1.0"
27252725
postcss "^8.4.33"

0 commit comments

Comments
 (0)