# esbuild-plugin-alias-path

> ESBuild plugin for alias path.

Latest version **2.0.2** (published 2022-11-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install esbuild-plugin-alias-path
pnpm add esbuild-plugin-alias-path
yarn add esbuild-plugin-alias-path
bun add esbuild-plugin-alias-path
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2022-11-21 |
| First published | 2021-04-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 13.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 118 |
| Author | Linbudu |
| Maintainers | linbudu |
| Keywords | ESBuild, plugin |

## Links

- npm: https://www.npmjs.com/package/esbuild-plugin-alias-path
- Repository: https://github.com/LinbuduLab/esbuild-plugins
- Homepage: https://github.com/LinbuduLab/esbuild-plugins/tree/master/packages/esbuild-plugin-copy#readme
- Issues: https://github.com/LinbuduLab/esbuild-plugins/issues
- npm.io page: https://npm.io/package/esbuild-plugin-alias-path

## Dependencies (3)

- [find-up](https://npm.io/package/find-up.md) 5.0.0
- [fs-extra](https://npm.io/package/fs-extra.md) ^10.1.0
- [jsonfile](https://npm.io/package/jsonfile.md) ^6.1.0

## Alternatives

- [raw-loader](https://npm.io/package/raw-loader.md) — 4.3M weekly downloads
- [plop](https://npm.io/package/plop.md) — 1.4M weekly downloads
- [webpack-deadcode-plugin](https://npm.io/package/webpack-deadcode-plugin.md) — 80.3K weekly downloads
- [@storybook/preact-vite](https://npm.io/package/@storybook/preact-vite.md) — 54.2K weekly downloads
- [vite-plugin-transform](https://npm.io/package/vite-plugin-transform.md) — 2.4K weekly downloads

## Recent versions

- 2.0.2 (latest) — 2022-11-21
- 1.1.1-beta.1 (beta) — 2022-11-17
- 2.0.1 — 2022-11-21
- 2.0.0 — 2022-11-17
- 1.1.1 — 2022-03-05
- 1.0.1 — 2022-03-05
- 1.0.0 — 2021-10-02
- 0.4.0 — 2021-09-20
- 0.3.3 — 2021-09-09
- 0.2.3 — 2021-05-27
- 0.2.1 — 2021-05-25
- 0.2.0 — 2021-05-23
- 0.1.0 — 2021-05-17
- 0.0.1-1 — 2021-04-20

## README

# esbuild-plugin-alias-path

ESBuild plugin for alias path replacement.

- [Author](https://github.com/linbudu599)
- [GitHub Repo](https://github.com/LinbuduLab/esbuild-plugins/tree/master/packages/esbuild-plugin-alias-path#readme)
- [Changelog](https://github.com/LinbuduLab/esbuild-plugins/blob/main/packages/esbuild-plugin-alias-path/CHANGELOG.md)

## Usage

```bash
npm install esbuild-plugin-alias-path --save-dev
pnpm install esbuild-plugin-alias-path --save-dev
yarn add esbuild-plugin-alias-path --save-dev
```

```typescript
import { build } from 'esbuild';
import { aliasPath } from 'esbuild-plugin-alias-path';

(async () => {
  const res = await build({
    entryPoints: ['./src/main.ts'],
    bundle: true,
    outfile: './dist/main.js',
    plugins: [
      aliasPath({
        alias: { '@foo': './src/alias/foo.ts' },
      }),
    ],
  });
})();

// src/main.ts
import { FOO } from '@foo';
console.log(FOO);

// src/alias/foo.ts
export const FOO = 'foo';

// Output dist/main.js
import { FOO } from './src/alias/foo.ts';
```

## Configurations

You can also use syntax `*` like `@alias/*`, this will explore all the files in the directory and replace the path.

> Use `@alias/*` instead of `@alias/**/*`

```typescript
aliasPath({
  alias: {
    '@alias/*': path.resolve(__dirname, './src/alias'),
  },
});
```

For example:

```text
|- alias
|- |- foo.ts
|-- nested
|-- |- bar.ts
```

Will be replaced to:

```text
@alias/foo.ts -> ./src/alias/foo.ts
@alias/nested/bar.ts -> ./src/alias/nested/bar.ts

```

**NOTE: In TypeScript project, `compilerOptions.paths` in `tsconfig.json` will be used by ESBuild automatically, so you will need this plugin only when you're going to replace the alias dynamically.**

---
_Source: https://npm.io/package/esbuild-plugin-alias-path · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
