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-aliases

v0.11.7

Published

Alias auto generation for Vite

Downloads

34,832

Readme

Usage

Install

npm i vite-aliases -D

Add it to vite.config.js

// vite.config.js
import { ViteAliases } from 'vite-aliases'

export default {
  plugins: [
    ViteAliases()
  ]
};

Add this to package.json (Plugin is only available for ESM)

{
  "type": "module"
}

That's it!

src
  assets
  components
  pages
  store
  utils

will generate the following:

[
  {
    find: '@',
    replacement: '${your_project_path}/src'
  },
  {
    find: '@assets',
    replacement: '${your_project_path}/src/assets'
  },
  {
    find: '@components',
    replacement: '${your_project_path}/src/components'
  },
  {
    find: '@pages',
    replacement: '${your_project_path}/src/pages'
  },
  {
    find: '@store',
    replacement: '${your_project_path}/src/store'
  },
  {
    find: '@utils',
    replacement: '${your_project_path}/src/utils'
  },
]

Best Practice

vite-aliases is meant to simply take the first Layer of your folders and turn it into useful Shortcuts. Therefore i advise you to use the default Configuration and not use folders with the same name, otherwise it will create an Error.

If however you need duplicate Foldernames, enable adjustDuplicates. This will turn the entire Filepath of said duplicate into the alias itself, like shown in the Example below.

Example:

`src/components` -> `@components`
`src/pages/components` -> `@pagesComponents`
`src/test/new/partials/components` -> `@testNewPartialsComponents`

and so on..

Configuration

Current available options:

ViteAliases({
  /**
  * Relative path to the project directory
  */
  dir: 'src',

  /**
  * Prefix symbol for the aliases
  */
  prefix: '~',

  /**
  * Allow searching for subdirectories
  */
  deep: true,

  /**
  * Search depthlevel for subdirectories
  */
  depth: 1,

  /**
  * Creates a Logfile
  * use `logPath` to change the location
  */
  createLog: false,

  /**
  * Path for Logfile
  */
  logPath: 'src/logs',

  /**
  * Create global project directory alias
  */
  createGlobalAlias: true,

  /**
  * Turns duplicates into camelCased path aliases
  */
  adjustDuplicates: false,

  /**
  * Used paths in JS/TS configs will now be relative to baseUrl
  */
  useAbsolute: false,

  /**
  * Adds seperate index paths
  * approach created by @davidohlin
  */
  useIndexes: false,

  /**
  * Generates paths in IDE config file
  * works with JS or TS
  */
  useConfig: true,

  /**
  * Override config paths
  */
  ovrConfig: false,

  /**
  * Will generate Paths in tsconfig
  * used in combination with `useConfig`
  * Typescript will be auto detected
  */
  dts: false,

  /**
  * Disables any terminal output
  */
  silent: true,

  /**
  * Root path of Vite project
  */
  root: process.cwd()
});

Thanks

Thanks to @brattonross and @antfu, due to this tiny library beeing inspired by both projects:

vite-plugin-voie

unplugin-vue-components.

License

MIT License © 2020-PRESENT Leon Langer