This extension is for sorting ES6 imports for Javascript files (.js
, .jsx
, .ts
, .tsx
) using Renke's excellent import-sort tool. Sorting happens in-place and overwrites the file with sorted imports.
This extension also installs import-sort-cli
and import-sort-style-eslint
packages as devDependencies
in the project.
-
Open the file palette Ctrl+P (Cmd+P on Mac) and enter the following command,
ext install developertejasjadhav.javascript-refactor--sort-imports
-
Install the required parser for your language.
# Using NPM npm install --save-dev import-sort-parser-babylon # For Javascript npm install --save-dev import-sort-parser-typescript # For Typescript # Using Yarn yarn add --dev import-sort-parser-babylon # For Javascript yarn add --dev import-sort-parser-typescript # For Typescript
-
Create a
.importsortrc.js
file in the root of your project.module.exports = { // Only for Javascript. '.js, .jsx': { parser: 'babylon', }, // Only for Typescript. '.ts, .tsx': { parser: 'typescript', }, }
- Open the Javascript file in the editor.
- Open the command palette Ctrl+Shift+P and enter Javascript Refactor: Sort Imports.
By default, the sorting happens using import-sort-style-eslint
. You can choose any available style on Github.
-
Install the import style,
# Using NPM npm install --save-dev import-sort-style-<your style> # Using Yarn yarn add --dev import-sort-style-<your style>
-
Edit the
.importsortrc.js
file in your project root. -
Add the
style
parameter for the extensions,module.exports = { '.js, .jsx, .ts, .tsx': { style: '<your style>' } }
Version | Description |
---|---|
0.0.1 | First alpha release. |
0.0.2 | Added support for .tsx . |
0.0.3 | Added support for latest import-sort-cli . |
0.0.4 | Fixed bugs in previous release. |
0.0.5 | Fixed NPM security vulnerabilities. |
0.0.6 | Added "Install CLI using Yarn" option. |