Prettier plugin that rewrites local import and export specifiers to the shortest path depth based on tsconfig.json or jsconfig.json paths mappings. Version 0.0.3, released early 2023, with no further updates since. Supports .js, .jsx, .ts, .tsx, and .vue files, preserving file extensions and normalizing to POSIX separators. It compares relative paths and path aliases, keeping the shortest depth, and skips specifiers resolving to node_modules or outside the project root. Differentiators: integrates with Prettier formatting, avoids long relative paths, respects existing TypeScript/JavaScript path aliases, and merges paths from extended tsconfig chains.
npm install prettier-plugin-shorten-importsVerified import paths — ran on the pinned version, not inferred.
Set up a tsconfig alias, create a file with a long relative import, and run Prettier to shorten it.
Manually update dynamic specifiers if needed; plugin only handles static import/export statements.
Ensure specifiers point inside the project; external specifiers are left unchanged.
If you need to rewrite external script src attributes, handle them separately.
Ensure the closest tsconfig to the file has the desired paths configuration.
Consider using an alternative plugin like prettier-plugin-organize-imports or prettier-plugin-import-sort if issues arise.
Install typescript: npm install --save-dev typescript
Upgrade Prettier: npm install --save-dev prettier@latest
Ensure a tsconfig.json or jsconfig.json exists in the project root or above the target file.