Skip to content

chore: eslint migration #1137

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

Merged
merged 8 commits into from
Aug 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .eslintignore

This file was deleted.

5 changes: 0 additions & 5 deletions .eslintrc.js

This file was deleted.

14 changes: 8 additions & 6 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,13 @@ jobs:
- name: Install dependencies (old Node.js version)
run: |
rm package-lock.json
npm install --ignore-engines
if: matrix.node-version == '12.x' || matrix.node-version == '14.x' || matrix.node-version == '16.x'
npm install --ignore-engines --ignore-scripts
npm install -D typescript@4
if: matrix.node-version == '12.x' || matrix.node-version == '14.x' || matrix.node-version == '16.x' || matrix.node-version == '18.x'

- name: Install dependencies
run: npm ci
if: matrix.node-version == '18.x' || matrix.node-version == '20.x' || matrix.node-version == '22.x' || matrix.node-version == '24.x'
if: matrix.node-version == '20.x' || matrix.node-version == '22.x' || matrix.node-version == '24.x'

- name: Install webpack ${{ matrix.webpack-version }}
if: matrix.webpack-version != 'latest'
Expand Down Expand Up @@ -157,12 +158,13 @@ jobs:
- name: Install dependencies (old Node.js version)
run: |
rm package-lock.json
npm install --ignore-engines
if: matrix.node-version == '12.x' || matrix.node-version == '14.x' || matrix.node-version == '16.x'
npm install --ignore-engines --ignore-scripts
npm install -D typescript@4
if: matrix.node-version == '12.x' || matrix.node-version == '14.x' || matrix.node-version == '16.x' || matrix.node-version == '18.x'

- name: Install dependencies
run: npm ci
if: matrix.node-version == '18.x' || matrix.node-version == '20.x' || matrix.node-version == '22.x' || matrix.node-version == '24.x'
if: matrix.node-version == '20.x' || matrix.node-version == '22.x' || matrix.node-version == '24.x'

- name: Run tests for webpack version latest with experimentalUseImportModule
run: npm run test:coverage -- --ci
Expand Down
48 changes: 20 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ Allows to override default behavior and insert styles at any position.

```js
new MiniCssExtractPlugin({
insert: function (linkTag) {
var reference = document.querySelector("#some-element");
insert(linkTag) {
const reference = document.querySelector("#some-element");
if (reference) {
reference.parentNode.insertBefore(linkTag, reference);
}
Expand All @@ -217,7 +217,7 @@ A new `<link>` tag will be inserted before the element with the ID `some-element
Type:

```ts
type attributes = Record<string, string>};
type attributes = Record<string, string>;
```

Default: `{}`
Expand Down Expand Up @@ -483,9 +483,8 @@ module.exports = {
{
loader: MiniCssExtractPlugin.loader,
options: {
publicPath: (resourcePath, context) => {
return path.relative(path.dirname(resourcePath), context) + "/";
},
publicPath: (resourcePath, context) =>
`${path.relative(path.dirname(resourcePath), context)}/`,
},
},
"css-loader",
Expand Down Expand Up @@ -620,6 +619,7 @@ For `development` mode (including `webpack-dev-server`) you can use [style-loade

```js
const MiniCssExtractPlugin = require("mini-css-extract-plugin");

const devMode = process.env.NODE_ENV !== "production";

module.exports = {
Expand All @@ -638,7 +638,7 @@ module.exports = {
},
],
},
plugins: [].concat(devMode ? [] : [new MiniCssExtractPlugin()]),
plugins: [devMode ? [] : [new MiniCssExtractPlugin()]].flat(),
};
```

Expand Down Expand Up @@ -702,7 +702,7 @@ module.exports = {
**index.js**

```js
import { fooBaz, bar } from "./styles.css";
import { bar, fooBaz } from "./styles.css";

console.log(fooBaz, bar);
```
Expand Down Expand Up @@ -767,12 +767,11 @@ module.exports = {
{
loader: MiniCssExtractPlugin.loader,
options: {
publicPath: (resourcePath, context) => {
publicPath: (resourcePath, context) =>
// publicPath is the relative path of the resource to the context
// e.g. for ./css/admin/main.css the publicPath will be ../../
// while for ./css/main.css the publicPath will be ../
return path.relative(path.dirname(resourcePath), context) + "/";
},
`${path.relative(path.dirname(resourcePath), context)}/`,
},
},
"css-loader",
Expand All @@ -797,8 +796,9 @@ You should not use `HotModuleReplacementPlugin` plugin if you are using a `webpa
**webpack.config.js**

```js
const webpack = require("webpack");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const webpack = require("webpack");

const devMode = process.env.NODE_ENV !== "production";

const plugins = [
Expand Down Expand Up @@ -848,8 +848,8 @@ You should not use `HotModuleReplacementPlugin` plugin if you are using a `webpa
**webpack.config.js**

```js
const webpack = require("webpack");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const webpack = require("webpack");

const plugins = [
new MiniCssExtractPlugin({
Expand Down Expand Up @@ -890,8 +890,8 @@ To minify the output, use a plugin like [css-minimizer-webpack-plugin](https://g
**webpack.config.js**

```js
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");

module.exports = {
plugins: [
Expand Down Expand Up @@ -992,17 +992,13 @@ module.exports = {
fooStyles: {
type: "css/mini-extract",
name: "styles_foo",
chunks: (chunk) => {
return chunk.name === "foo";
},
chunks: (chunk) => chunk.name === "foo",
enforce: true,
},
barStyles: {
type: "css/mini-extract",
name: "styles_bar",
chunks: (chunk) => {
return chunk.name === "bar";
},
chunks: (chunk) => chunk.name === "bar",
enforce: true,
},
},
Expand Down Expand Up @@ -1129,7 +1125,7 @@ module.exports = {
{
loader: "sass-loader",
options: {
additionalData: `@use 'dark-theme/vars' as vars;`,
additionalData: "@use 'dark-theme/vars' as vars;",
},
},
],
Expand All @@ -1141,7 +1137,7 @@ module.exports = {
{
loader: "sass-loader",
options: {
additionalData: `@use 'light-theme/vars' as vars;`,
additionalData: "@use 'light-theme/vars' as vars;",
},
},
],
Expand All @@ -1163,7 +1159,7 @@ module.exports = {

**src/index.js**

```js
```
import "./style.scss";

let theme = "light";
Expand All @@ -1172,7 +1168,6 @@ const themes = {};
themes[theme] = document.querySelector("#theme");

async function loadTheme(newTheme) {
// eslint-disable-next-line no-console
console.log(`CHANGE THEME - ${newTheme}`);

const themeElement = document.querySelector("#theme");
Expand All @@ -1182,7 +1177,6 @@ async function loadTheme(newTheme) {
}

if (themes[newTheme]) {
// eslint-disable-next-line no-console
console.log(`THEME ALREADY LOADED - ${newTheme}`);

document.head.appendChild(themes[newTheme]);
Expand All @@ -1191,13 +1185,11 @@ async function loadTheme(newTheme) {
}

if (newTheme === "dark") {
// eslint-disable-next-line no-console
console.log(`LOADING THEME - ${newTheme}`);

import(/* webpackChunkName: "dark" */ "./style.scss?dark").then(() => {
themes[newTheme] = document.querySelector("#theme");

// eslint-disable-next-line no-console
console.log(`LOADED - ${newTheme}`);
});
}
Expand Down Expand Up @@ -1275,7 +1267,7 @@ MiniCssExtractPlugin.getCompilationHooks(compilation).beforeTagInsert.tap(
Template.asString([
source,
`${varNames.tag}.setAttribute("href", "https://github.com/webpack-contrib/mini-css-extract-plugin");`,
])
]),
);
```

Expand Down
14 changes: 14 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineConfig, globalIgnores } from "eslint/config";
import configs from "eslint-config-webpack/configs.js";

export default defineConfig([
globalIgnores([
"test/**/cases/**/*",
"test/manual/**/*",
"!test/cases/webpack.config.js",
"test/js/**/*",
]),
{
extends: [configs["recommended-dirty"]],
},
]);
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
prettierPath: require.resolve("prettier-2"),
transformIgnorePatterns: ["/node_modules/", "<rootDir>/dist/"],
watchPathIgnorePatterns: ["<rootDir>/test/js"],
setupFilesAfterEnv: ["<rootDir>/setupTest.js"],
Expand Down
Loading
Loading