Skip to content

johvin/eslint-import-resolver-alias

Repository files navigation

eslint-import-resolver-alias

Version npm Build Status Download Dependencies Coverage Status Known Vulnerabilities License

This is a simple Node.js module import resolution plugin for eslint-plugin-import, which supports module alias and native Node.js module import.

Installation

Prerequisites: Node.js >=4.x and corresponding version of npm.

npm install eslint-plugin-import eslint-import-resolver-alias --save-dev

Usage

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 module helper/* 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

CHANGELOG

CHANGELOG

References

  • eslint-plugin-import/no-extraneous-dependencies
  • eslint-plugin-import/no-unresolved
  • eslint-module-utils/resolve
  • resolve
  • eslint-import-resolver-node

About

a simple Node behavior import resolution plugin for eslint-plugin-import, supporting module alias

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published