npm.io
0.1.0 • Published 3 years ago

unplugin-alias

Licence
MIT
Version
0.1.0
Deps
3
Size
24 kB
Vulns
0
Weekly
0

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
// vite.config.ts
import Alias from "unplugin-alias/vite"

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


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

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


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


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


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

This module works for both Nuxt 2 and Nuxt Vite


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


esbuild

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


Keywords