0.1.0 • Published 7 months ago

unplugin-alias v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

unplugin-alias

NPM version

This unplugin helps you to setup alias for your bundler automatically by loading your tsconfig.json with its compilerOptions.paths field.

And if you use some other runtime, such as JITI, you can use the function mapPathToAlias to setup manually.

Install

pnpm i unplugin-alias

Usage

export interface Options {
  configFile?: string
  cwd?: string
}
// vite.config.ts
import Alias from "unplugin-alias/vite"

export default defineConfig({
  plugins: [
    Alias({
      /* options */
    }),
  ],
})

// rollup.config.js
import Alias from "unplugin-alias/rollup"

export default {
  plugins: [
    Alias({
      /* options */
    }),
  ],
}

// webpack.config.js
module.exports = {
  /* ... */
  plugins: [
    require("unplugin-alias/webpack")({
      /* options */
    }),
  ],
}

// rspack.config.js
module.exports = {
  /* ... */
  plugins: [
    require("unplugin-alias/rspack")({
      /* options */
    }),
  ],
}

// nuxt.config.js
export default defineNuxtConfig({
  modules: [
    [
      "unplugin-alias/nuxt",
      {
        /* options */
      },
    ],
  ],
})

This module works for both Nuxt 2 and Nuxt Vite

// vue.config.js
module.exports = {
  configureWebpack: {
    plugins: [
      require("unplugin-alias/webpack")({
        /* options */
      }),
    ],
  },
}

Esbuild supports alias out-of-box, so you don't need this plugin.