This is a simple Node.js module import resolution plugin for eslint-plugin-import
, which supports module alias and native Node.js module import.
Prerequisites: Node.js >=4.x and corresponding version of npm.
npm install eslint-plugin-import eslint-import-resolver-alias --save-dev
Pass this resolver and its parameters to eslint-plugin-import
using your eslint
config file, .eslintrc
or .eslintrc.js
.
// .eslintrc.js
module.exports = {
settings: {
'import/resolver': {
'alias': [
['babel-polyfill', 'babel-polyfill/dist/polyfill.min.js'],
['helper', './utils/helper'],
['material-ui/DatePicker', '../custom/DatePicker'],
['material-ui', 'material-ui-ie10']
],
// node: true
}
}
};
Note:
- The items of alias config array is also array which contains 2 string
- The first string represents the mapped module name or path
- The second string represents the module alias, the actual module path os module name
- The config item
['helper', './utils/helper']
means that the modulehelper/*
will be resolved to./utils/helper/*
. See #3 - The order of 'material-ui/DatePicker' and 'material-ui' cannot be reversed, otherwise the alias rule 'material-ui/DatePicker' does not work
- when the config is an empty array or not an array, the resolver falls back to native Node.js module import
- eslint-plugin-import/no-extraneous-dependencies
- eslint-plugin-import/no-unresolved
- eslint-module-utils/resolve
- resolve
- eslint-import-resolver-node