# vite-jsconfig-paths

> Vite resolver for JavaScript compilerOptions.paths

Latest version **2.0.1** (published 2022-04-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install vite-jsconfig-paths
pnpm add vite-jsconfig-paths
yarn add vite-jsconfig-paths
bun add vite-jsconfig-paths
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2022-04-04 |
| First published | 2022-04-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 53.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | EliezerSPP |
| Maintainers | eliezerspp |
| Keywords | vite, resolver, jsconfig, paths |

## Links

- npm: https://www.npmjs.com/package/vite-jsconfig-paths
- Repository: https://github.com/EliezerSPP/vite-tsconfig-paths
- npm.io page: https://npm.io/package/vite-jsconfig-paths

## Dependencies (4)

- [debug](https://npm.io/package/debug.md) ^4.1.1
- [globrex](https://npm.io/package/globrex.md) ^0.1.2
- [recrawl-sync](https://npm.io/package/recrawl-sync.md) ^2.0.3
- [tsconfig-paths](https://npm.io/package/tsconfig-paths.md) ^3.9.0

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 2.0.1 (latest) — 2022-04-04
- 2.0.0 — 2022-04-04
- 1.0.0 — 2022-04-04

## README

# vite-jsconfig-paths

[![npm](https://img.shields.io/npm/v/vite-jsconfig-paths.svg)](https://www.npmjs.com/package/vite-jsconfig-paths)
[![Code style: Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)

Give [`vite`] the ability to resolve imports using "jsconfig.json" path mapping.

Based on: [vite-tsconfig-paths](https://github.com/aleclarson/vite-tsconfig-paths)

[`vite`]: https://github.com/vitejs/vite

## Usage

1. Install as dev dependency

2. Inject `vite-jsconfig-paths` using the `vite.config.js` module

   ```js
   import { defineConfig } from 'vite'
   import jsconfigPaths from 'vite-jsconfig-paths'

   export default defineConfig({
     plugins: [jsconfigPaths()],
   })
   ```

**Note:** You need to restart Vite when you update your `paths` mappings.

### Options

- `root: string`  
  The directory to crawl for `jsconfig.json` files.  
  Defaults to `viteConfig.root`

- `projects: string[]`  
  An array of `jsconfig.json` paths (relative to `viteConfig.root`)
  and/or directories that contain a `jsconfig.json` file.  
  This overrides the `root` option.

- `extensions: string[]`  
  File extensions to search for.  
  Defaults to `.js | .jsx | .ts | .tsx | .mjs`

&nbsp;

### baseUrl

If the `baseUrl` is defined, it gets prepended to all bare imports, and its resolution will take precedence over node_modules. This is also how TypeScript does it.

Say the `baseUrl` is `../root` and you import `react`. This plugin will use `../root/react` if it exists. If not found, then `react` is resolved normally. The `baseUrl` is relative to the project root (where `jsconfig.json` lives).

&nbsp;

### include/exclude

The `include` and `exclude` compiler options are respected.

Internally, [globrex](https://github.com/terkelg/globrex) is used for glob matching.

&nbsp;

### Troubleshooting

The `DEBUG` environment variable can be used to figure out why this plugin isn't working as you may have expected.

```sh
DEBUG=vite-jsconfig-paths yarn vite
```

&nbsp;

---
_Source: https://npm.io/package/vite-jsconfig-paths · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
