This import-sort is based on import-sort-style-module.
- Install with
npm i -D @leanix/import-sort-style - If used with Prettier, install
npm i -D prettier-plugin-import-sort@0.0.3for Prettier@v1 andnpm i -D prettier-plugin-import-sortfor Prettier@v2
- Add a configuration like the following to your package.json to specify the parser (which may need to be installed separately) and the corresponding extensions:
"importSort": {
".js, .ts": {
"style": "@leanix/import-sort-style",
"parser": "typescript",
"options": {
"prefixes": [
"@app",
"@lib"
]
}
}
}
- The list of local prefixes/aliases is optional.
The order of imports is:
- Third-party modules with side effects are not sorted because order may matter, e.g.
import 'polyfills'; - Local, absolute modules with side-effects are not sorted because order may matter, e.g.
import '@app/polyfills'; - Local, relative modules with side effects are not sorted because order may matter, e.g.
import './polyfills'; - Third-party modules are sorted by name, e.g.
import { endOfMonth } from 'date-fns'; - Built-in Node.js modules are sorted by name, e.g.
import * as fs from 'fs'; - Local, absolute modules are sorted by the prefix-order provided and then by name
import { LIMIT } from '@app/app.constants'; - Local, relative modules are sorted by "relative depth" and then by name
import { LIMIT } from './app.constants';
See the tests for more examples.
Copyright 2020 LeanIX GmbH under the Unlicense license.