npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vite-resolve-tsconfig-paths

v0.0.9

Published

A Vite plugin that resolves TypeScript compilerOptions.paths.

Downloads

150

Readme

vite-resolve-tsconfig-paths

Resolve Typescript paths (tsconfig paths) in your Vite project.

Usage

Install

npm install -D vite-resolve-tsconfig-paths

Add to vite.config.js

// vite.config.js
import { defineConfig } from "vite";
import { tsConfigPaths } from "vite-resolve-tsconfig-paths";

export default defineConfig({
  plugins: [tsConfigPaths()],
});

Options

Currently none. Some coming soon.

FAQ

Why this plugin?

Why use this plugin when there are several alternatives (I know, I struggled to find an available npm package name), and some are far more used, more mature? Great question. You don't have to! I created this plugin to solve a problem I had; the main existing option doesn't support extends or references in a sub-directory. I did actually draft a fix for that library, but in my travels I decided that there was probably a "better" approach to solving the problem. So this library was born.

Does it support references or extends in a sub-folder?

Yes. That was the main reason I created it.

Does it support ${configDir}?

In theory yes. I haven't tested it yet. Test it, let me know.

How it works

When the Vite plugin hook configResolved is run, the plugin (using tsconfck) looks for all tsconfig.json project files within the project root.

The plugin will then process all these tsconfig.json files (including references), and parse the config.

Parsing the config file gives the final compilerOptions, including values from extended configs.

The parsing uses tsconfck's parseNative, so the result should be as comparable with the expected result as that library is capable of.

For each parsed result with paths in compilerOptions, the plugin will create a "resolver" function. This resolver function takes a Vite request id and attempts to resolve it relative to the baseUrl using tsconfig-paths.

In the Vite resolveId hook, the plugin checks each request, to see if the resolvers should be applied.

If there is an importer, the request id is not relative, and the request is not a file system absolute path (i.e. it is an alias import), the plugin applies all the resolvers created earlier until one matches.

Prior art

This plugin was inspired by, and borrows some logic (checking request ids to see if resolvers should be applied) from https://github.com/aleclarson/vite-tsconfig-paths, however we've taken a significantly different approach to solving the problem.

Contributing

Contributions are super welcome.

Developing

Clone the repo

git clone https://github.com/sebtoombs/vite-resolve-tsconfig-paths.git

Install dependencies

npm install

Write some code!

Build

npm run build

Don't forget, to pass CI, your code will need to pass npm run lint, npm run format:check & npm run build

Share your contribution

To make a contribution;

  • Fork this repo
  • Create a branch for your change, branch naming is not important
  • Open a Pull Request against the main branch of this repo
    • PR title, labels etc are (at this stage) not important
  • Wait for a review
  • If approved, squash and merge
  • Your change will be included in the next release!