# absolute-module-mapper-plugin

> The plugin on enhanced-resolver to map module path

Latest version **1.3.1** (published 2020-02-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install absolute-module-mapper-plugin
pnpm add absolute-module-mapper-plugin
yarn add absolute-module-mapper-plugin
bun add absolute-module-mapper-plugin
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.1 |
| Published | 2020-02-18 |
| First published | 2019-11-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8 |
| Dependencies | 1 |
| Unpacked size | 17.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | imcuttle |
| Maintainers | moyuyc |
| Keywords | imcuttle, absolute, module, mapper, plugin, absolute-module-mapper-plugin, webpack, enhanced-resolve |

## Links

- npm: https://www.npmjs.com/package/absolute-module-mapper-plugin
- Repository: https://github.com/imcuttle/absolute-module-mapper-plugin
- Homepage: https://github.com/imcuttle/absolute-module-mapper-plugin#readme
- Issues: https://github.com/imcuttle/absolute-module-mapper-plugin/issues
- npm.io page: https://npm.io/package/absolute-module-mapper-plugin

## Dependencies (1)

- [minimatch](https://npm.io/package/minimatch.md) ^3.0.4

## 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.3.1 (latest) — 2020-02-18
- 1.3.0 — 2020-02-16
- 1.2.4 — 2020-02-13
- 1.2.3 — 2020-02-13
- 1.2.2 — 2020-02-13
- 1.2.1 — 2019-11-14
- 1.2.0 — 2019-11-13
- 1.0.0 — 2019-11-09

## README

# absolute-module-mapper-plugin

[![Build status](https://img.shields.io/travis/imcuttle/absolute-module-mapper-plugin/master.svg?style=flat-square)](https://travis-ci.org/imcuttle/absolute-module-mapper-plugin)
[![Test coverage](https://img.shields.io/codecov/c/github/imcuttle/absolute-module-mapper-plugin.svg?style=flat-square)](https://codecov.io/github/imcuttle/absolute-module-mapper-plugin?branch=master)
[![NPM version](https://img.shields.io/npm/v/absolute-module-mapper-plugin.svg?style=flat-square)](https://www.npmjs.com/package/absolute-module-mapper-plugin)
[![NPM Downloads](https://img.shields.io/npm/dm/absolute-module-mapper-plugin.svg?style=flat-square&maxAge=43200)](https://www.npmjs.com/package/absolute-module-mapper-plugin)
[![Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://prettier.io/)
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg?style=flat-square)](https://conventionalcommits.org)

> The plugin on enhanced-resolver to map module path

It's helpful when we need to adjust third-party library dependencies. for example:

We have the follow project directory tree now.
```text
project/
   node_modules/
      antd/
         lib/
            components/
               icon/
                  index.js
               button/
                  index.js  # requires icon/index.js
               ... 
   wrapper/
      button/
         index.js
      icon/
         index.js
```

And the point is `antd/button` requires `antd/icon`, but we prefer it requires `wrapper/icon` which we can customize.

So we could use this plugin in webpack, let `antd/icon` in `antd/button` is mapped to `wrapper/icon`.

## Installation

```bash
npm install absolute-module-mapper-plugin
# or use yarn
yarn add absolute-module-mapper-plugin
```

## Usage in webpack

```javascript
const AbsoluteModuleMapperPlugin = require('absolute-module-mapper-plugin')

const webpackConfig = {
   resolve: {
      plugins: [
         new AbsoluteModuleMapperPlugin({
            root: '/project',
            include: [
               '<root>/node_modules/antd/lib/components/button'
            ],
            mapper: {
               '^<root>/node_modules/antd/lib/components/icon/index.js': '<root>/wrapper/icon/index.js'
            }
         })
      ]
   }
}
```

## Options

### `silent`
Show some runtime log
- Default: `true`

### `root`
Assign root path, it is the value for `<root>` placeholder.

- Type: `string`

### `include`
The included paths for mapping

- Type: `Array<string|Function|RegExp>`
- Default: `[options.root]`

### `exclude`
The excluded paths for mapping

- Type: `Array<string|Function|RegExp>`
- Default: `[]`

### `mapper`

absolute filename mapper.

- Type: `(filename, ctx) => string | (filename, ctx, callback) => void  | {}`
- Example
```javascript
{
   '^<root>/from/(\w+)': '<root>/to/$1'
}
```

### `requestMapper`

request mapper.

- Type: `(request, ctx) => string | (request, ctx, callback) => void | {}`
- Example
```javascript
{
   '^./a.js$': './b.js'
}
```

## Contributing

- Fork it!
- Create your new branch:  
  `git checkout -b feature-new` or `git checkout -b fix-which-bug`
- Start your magic work now
- Make sure npm test passes
- Commit your changes:  
  `git commit -am 'feat: some description (close #123)'` or `git commit -am 'fix: some description (fix #123)'`
- Push to the branch: `git push`
- Submit a pull request :)

## Authors

This library is written and maintained by imcuttle, <a href="mailto:moyuyc95@gmail.com">moyuyc95@gmail.com</a>.

## License

MIT - [imcuttle](https://github.com/imcuttle) 🐟

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