# dynamic-alias-resolve-plugin

> dynamic alias resolve plugin

Latest version **1.4.1** (published 2023-10-28) · ISC license · 0 weekly downloads

## Install

```sh
npm install dynamic-alias-resolve-plugin
pnpm add dynamic-alias-resolve-plugin
yarn add dynamic-alias-resolve-plugin
bun add dynamic-alias-resolve-plugin
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.4.1 |
| Published | 2023-10-28 |
| First published | 2020-06-12 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 72 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | gqzhang5 |
| Maintainers | gqzhang5 |
| Keywords | enhanced-resolve, plugins, dynamic alias resolve plugin |

## Links

- npm: https://www.npmjs.com/package/dynamic-alias-resolve-plugin
- Repository: https://github.com/heiseshandian/dynamic-alias-resolve-plugin
- Homepage: https://github.com/heiseshandian/dynamic-alias-resolve-plugin#readme
- Issues: https://github.com/heiseshandian/dynamic-alias-resolve-plugin/issues
- npm.io page: https://npm.io/package/dynamic-alias-resolve-plugin

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 1.4.1 (latest) — 2023-10-28
- 1.3.1 — 2023-10-28
- 1.2.1 — 2021-11-07
- 1.1.1 — 2021-11-07
- 1.1.0 — 2021-11-07
- 1.0.7 — 2020-06-17
- 1.0.6 — 2020-06-17
- 1.0.5 — 2020-06-17
- 1.0.4 — 2020-06-16
- 1.0.3 — 2020-06-16
- 1.0.2 — 2020-06-16
- 1.0.1 — 2020-06-12
- 1.0.0 — 2020-06-12

## README

# dynamic-alias-resolve-plugin

![](assets/2020-06-12-10-12-59.png)

## Introduction

Thanks for the help of [enhanced-resolve](https://github.com/webpack/enhanced-resolve), we can define alias for path, but it's static, in some cases we may want alias point to A path or B path, in other words, we want dynamic alias. [enhanced-resolve](https://github.com/webpack/enhanced-resolve) is based on [tapable](https://github.com/webpack/tapable), so we can write a plugin to make it.

Read this in other languages: [english](./README.md), [简体中文](./README.zh-cn.md)

## Prerequisites

This module requires webpack v4 and above.

## Installation

```sh
npm install -D dynamic-alias-resolve-plugin
```

## Usage

In your webpack config, require() the dynamic-alias-resolve-plugin plugin as follows:

```js
const DynamicAliasResolvePlugin = require("dynamic-alias-resolve-plugin");
```

and finally, add the plugin to your resolve configuration's plugins array

```js
// https://webpack.js.org/configuration/resolve/#resolveplugins
resolve: {
  plugins: [
    new DynamicAliasResolvePlugin({
      // alias you want to make it dynamic
      alias: "@",
      // pathA or pathB should be replaced with real path
      // "request" is raw request object from enhanced-resolve
      // "alias" is matched alias of current request.(eg. "@" in "@/login.less")
      dynamic: (request, alias) => "pathA or PathB",
      // we just want less file to be handled by this plugin
      pattern: /\.less$/,
    }),
  ];
}
```

## Options

| properties |                          type                           |              default              |
| :--------: | :-----------------------------------------------------: | :-------------------------------: |
|   alias    |                     Array\<string\>                     |               ['@']               |
|  dynamic   | function(request,alias)=>string\|null\|false\|undefined |             ()=>null              |
|  pattern   |                         RegExp                          |               /.\*/               |

## Description Of Options

### alias

alias you want to make it dynamic

### dynamic

return value should be `absolute path`,all false value('',false,null) will be ignored. `request` is raw enhanced-resolve request object, `alias` is current alias you want make it dynamic. (eg. "@" in "@/login.less")

### pattern

files needs handled by this plugin

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