1.1.2 • Published 6 years ago

eslint-import-resolver-alias v1.1.2

Weekly downloads
260,121
License
MIT
Repository
github
Last release
6 years ago

eslint-import-resolver-alias

Version npm Version node Build Status Download Dependencies peerDependencies Coverage Status Known Vulnerabilities License

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

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: {
        map: [
          ['babel-polyfill', 'babel-polyfill/dist/polyfill.min.js'],
          ['helper', './utils/helper'],
          ['material-ui/DatePicker', '../custom/DatePicker'],
          ['material-ui', 'material-ui-ie10']
        ],
        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 alias of module name or path
    • The second string represents the actual module name or path
  • The map item ['helper', './utils/helper'] means that the modules which match helper or helper/* will be resolved to ./utils/helper or ./utils/helper/* which are located relative to the process current working directory (almost the project root directory). If you just want to resolve helper to ./utils/helper, use ['^helper$', './utils/helper'] instead. See issue #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']
      ]
    }
  }
};

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
    }
  }
};
@npm.piece/eslint-config-npmpieceeslint-config-hubside@biletiniz/eslint-configeslint-config-cw@wildberries/boilerplate-eslint-config@hangar31/eslint-config-h31@conten2/eslint-config-typescripteslint-config-innovordereslint-config-japhyreact-eslint-config-basehao-base@leonzalion/eslint-config@leonzalion/eslintrc@qulture/eslint-config-base@zentus/eslint-config-esmeslint-config-leedavidcseslint-config-arsam@easy-going/eslint-config-vueeslint-config-zq@infinitebrahmanuniverse/nolb-eslint-i@soybeanjs/eslint-config-basic@rightinyourwheelhouse/eslint-config@wumijs/eslint-config@goodev323/eslint@goodev323/eslint-configeslint-config-soybeanjs-basemichaels-ssr@everything-registry/sub-chunk-1609@atlantjs.dev/eslint-coremoskit-rock-itmoskit-rock-it-felipe-2norylord-kit@finomenal/eslint-config-finomenalmoskit-rock-it-fixeslint-config-musui-vue2eslint-config-dylanjswm-cli-testwhouse-eslint-configteste-luizvlware-uiveeroll-vue-package@divvy-homes/eslint-config-divvyhomes@code-styling/eslint-config@clubdrei/eslint-config@clubdrei/eslint-plugin-clubdrei@codeleap/config@ctsx/eslint-config-base@daaaan/eslint-config@cyansalt/eslint-config@cyansalt/eslint-config-preset@cyber-walrus/eslint-config@cyber-walrus/eslint-plugin@cusbo/eslint-config@cwwilbur/eslint-config@cosmiccloud/style-guide@convenia/eslint-config-vue@d-matrix/eslint-config@democrance/eslint-config@c1495616js/eslint-config@by-association-only/eslint-config-unisian@rtkcd/eslint-config-rtkcd@payping/eslint-config-payping@rocketcms/dotfiles@voluspa/style-guideeslint-config-szjs2me-eslint-configjanlab-uilaviro-foreman-js-vendor-dev@hyperspaceinc/style-guide@hyperspaceinc/style-guide-core@atlantjs.dev/guardian@kwangure/eslint-config-svelte@netdata/eslint-config-netdata@aybykovskii/eslint-configmoskit-rock-it-felipe@energyaspects/eslint-config@handsomewolf/eslint-config@lntvow/eslint-config-basicui-lib-12traitsui-lib-solstenturbo-react-eslint@aipmorg/lint@arabasta/eslint-config@atlascommunity/eslint-config@astahmer/eslint-config-ts@aurorafe/eslint-config-base@arietta-studio/lint@avsb/utils@astral-frontend/eslint-config-ts-ui@alexandragr-ssr-micro/eslint-react@alljoint-next/eslint-config-vue@alljoint-next/eslint-config-vue3@bairong/fabric@bamdadsabbagh/eslint-config@ayahub/lint@barguide/dotfiles@bigbite/build-tools@buildersbank/eslint-config-builders@bshdo/eslint-config@cat-com/eslint-config
1.1.2

6 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.4

7 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago