This package has been deprecated

Author message:

this package has been deprecated

eslint-import-resolver-locals-alias

2.0.1 • Public • Published

eslint-import-resolver-locals-alias

Version npm Build Status Download Dependencies Coverage Status License

This is a simple Node.js module import resolution plugin for eslint-plugin-import, which supports native Node.js module resolution, module alias and custom file extensions. Also supports aliases for project modules.

Installation

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

npm install eslint-plugin-import eslint-import-resolver-locals-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: {
        map: [
          ['babel-polyfill', 'babel-polyfill/dist/polyfill.min.js'],
          ['helper', './utils/helper'],
          ['material-ui/DatePicker', '../custom/DatePicker'],
          ['material-ui', 'material-ui-ie10'],
          ['@project-module', 'module/path/'],
          ['project-module2', 'module2']
        ],
        extensions: ['.ts', '.js', '.jsx', '.json']
      }
    }
  }
};

Note:

  • The alias config object contains two properties, map and extensions, both of which are array types
  • The item of map array is also array type 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 or name
  • The map 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
  • The default value of extensions property is ['.js', '.json', '.node'] if it is assigned to an empty array or not specified.

If the extensions property is not specified, the config object can be simplified to the map array.

// .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'],
        ['@project-module', 'module/path/'],
        ['project-module2', 'module2']
      ]
    }
  }
};

When the config is not a valid object (such as true), the resolver falls back to native Node.js module resolution.

// .eslintrc.js
module.exports = {
  settings: {
    'import/resolver': {
      alias: true
    }
  }
};

Dependents (0)

Package Sidebar

Install

npm i eslint-import-resolver-locals-alias

Weekly Downloads

5

Version

2.0.1

License

MIT

Unpacked Size

9.11 kB

Total Files

4

Last publish

Collaborators

  • moodpulse