What is eslint-import-resolver-webpack?
The eslint-import-resolver-webpack package is an ESLint plugin that allows you to use Webpack's module resolution in your ESLint configuration. This is particularly useful for projects that use Webpack aliases or custom module resolution paths, ensuring that ESLint can correctly resolve and lint your imports.
What are eslint-import-resolver-webpack's main functionalities?
Webpack Configuration Integration
This feature allows you to specify a Webpack configuration file in your ESLint settings. ESLint will use this configuration to resolve modules, ensuring that your import statements are correctly validated.
{"settings":{"import/resolver":{"webpack":{"config":"webpack.config.js"}}}}
Custom Webpack Configuration
You can also provide a custom Webpack configuration directly within the ESLint settings. This is useful if you have a simple configuration or want to override specific settings for ESLint.
{"settings":{"import/resolver":{"webpack":{"config":{"resolve":{"alias":{"@components":"./src/components"}}}}}}}
Multiple Webpack Configurations
This feature allows you to specify multiple Webpack configuration files. ESLint will try to resolve modules using each configuration in the order they are provided.
{"settings":{"import/resolver":{"webpack":{"config":["webpack.config.dev.js","webpack.config.prod.js"]}}}}
Other packages similar to eslint-import-resolver-webpack
eslint-import-resolver-alias
The eslint-import-resolver-alias package allows you to define custom path aliases for module resolution in ESLint. Unlike eslint-import-resolver-webpack, it does not rely on a Webpack configuration file but instead uses a simpler alias configuration directly in the ESLint settings.
eslint-import-resolver-node
The eslint-import-resolver-node package is a simple resolver for Node.js-style module resolution. It does not support Webpack-specific features like aliases or custom module resolution paths, making it less flexible than eslint-import-resolver-webpack for projects that use Webpack.
eslint-import-resolver-typescript
The eslint-import-resolver-typescript package is designed for projects using TypeScript. It allows ESLint to resolve modules based on the TypeScript configuration file (tsconfig.json). This package is more suitable for TypeScript projects compared to eslint-import-resolver-webpack, which is more general-purpose.
eslint-import-resolver-webpack
Webpack-literate module resolution plugin for eslint-plugin-import
.
:boom: Only "synchronous" Webpack configs are supported at the moment.
If your config returns a Promise
, this will cause problems.
Consider splitting your asynchronous configuration to a separate config.
Published separately to allow pegging to a specific version in case of breaking
changes.
To use with eslint-plugin-import
, run:
npm i eslint-import-resolver-webpack -g
or if you manage ESLint as a dev dependency:
npm install eslint-import-resolver-webpack --save-dev
Will look for webpack.config.js
as a sibling of the first ancestral package.json
,
or a config
parameter may be provided with another filename/path either relative to the
package.json
, or a complete, absolute path.
If multiple webpack configurations are found the first configuration containing a resolve section will be used. Optionally, the config-index
(zero-based) setting can be used to select a specific configuration.
---
settings:
import/resolver: webpack
or with explicit config file name:
---
settings:
import/resolver:
webpack:
config: 'webpack.dev.config.js'
or with explicit config file index:
---
settings:
import/resolver:
webpack:
config: 'webpack.multiple.config.js'
config-index: 1
or with explicit config file path relative to your projects's working directory:
---
settings:
import/resolver:
webpack:
config: './configs/webpack.dev.config.js'
or with explicit config object:
---
settings:
import/resolver:
webpack:
config:
resolve:
extensions:
- .js
- .jsx
If your config relies on environment variables, they can be specified using the env
parameter. If your config is a function, it will be invoked with the value assigned to env
:
---
settings:
import/resolver:
webpack:
config: 'webpack.config.js'
env:
NODE_ENV: 'local'
production: true
Support
Get supported eslint-import-resolver-webpack with the Tidelift Subscription