» npm install prettier-plugin-organize-imports
How to automatically sort imports in VS Code?
node.js - prettier-plugin-sort-imports ignores import order - Stack Overflow
Is it possible to remove unused imports with Prettier?
Sorting Import statements in VS Code with Prettier
Videos
Looking at this GitHub comment, it seems like I should be able to add "editor.codeActionsOnSave": { "source.organizeImports": true } to .vscode/settings.json and have it "just work", but in my testing that doesn't work. How do you handle automatic import sorting for .vue files in Visual Studio Code?
» npm install prettier-plugin-sort-imports
You can use VS Code .vscode/settings.json to organize imports.
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
}
I don't think this is supported by default.
But you can use this prettier-plugin https://www.npmjs.com/package/prettier-plugin-organize-imports
For a basic install of the library run:
npm install --save-dev prettier-plugin-organize-imports
Then add "prettier-plugin-organize-imports" to the .prettierrc config file for prettier in the "plugins" list. For example:
{
"plugins": ["prettier-plugin-organize-imports"],
...
}
That configuration can also go into your package.json file:
"prettier": {
"plugins": [
"prettier-plugin-organize-imports"
]
}
» npm install prettier-plugin-imports
Here's one of the videos I made that helped many people with automatic sorting import statements in VS Code using Prettier. I hope it helps people around here as well.
Do let me know some feedback 🙂
https://youtu.be/QQWgN0_gUxI