Skip to content

import/no-webpack-loader-syntax Restriction

What it does

Forbids using Webpack loader syntax directly in import or require statements.

Why is this bad?

This loader syntax is non-standard, so it couples the code to Webpack. The recommended way to specify Webpack loader configuration is in a Webpack configuration file.

Examples

Examples of incorrect code for this rule:

javascript
import myModule from "my-loader!my-module";
import theme from "style!css!./theme.css";

var myModule = require("my-loader!./my-module");
var theme = require("style!css!./theme.css");

Examples of correct code for this rule:

javascript
import myModule from "./my-module";
import theme from "./theme.css";

var myModule = require("./my-module");
var theme = require("./theme.css");

How to use

To enable this rule using the config file or in the CLI, you can use:

json
{
  "plugins": ["import"],
  "rules": {
    "import/no-webpack-loader-syntax": "error"
  }
}
bash
oxlint --deny import/no-webpack-loader-syntax --import-plugin

References

Released under the MIT License.