https://github.com/imcuttle/absolute-module-mapper-plugin
The plugin on enhanced-resolver to map module path
https://github.com/imcuttle/absolute-module-mapper-plugin
Last synced: about 1 year ago
JSON representation
The plugin on enhanced-resolver to map module path
- Host: GitHub
- URL: https://github.com/imcuttle/absolute-module-mapper-plugin
- Owner: imcuttle
- License: mit
- Created: 2019-11-09T09:48:46.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T00:42:47.000Z (over 3 years ago)
- Last Synced: 2025-03-23T02:33:59.093Z (about 1 year ago)
- Language: JavaScript
- Size: 941 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: License
Awesome Lists containing this project
README
# absolute-module-mapper-plugin
[](https://travis-ci.org/imcuttle/absolute-module-mapper-plugin)
[](https://codecov.io/github/imcuttle/absolute-module-mapper-plugin?branch=master)
[](https://www.npmjs.com/package/absolute-module-mapper-plugin)
[](https://www.npmjs.com/package/absolute-module-mapper-plugin)
[](https://prettier.io/)
[](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: [
'/node_modules/antd/lib/components/button'
],
mapper: {
'^/node_modules/antd/lib/components/icon/index.js': '/wrapper/icon/index.js'
}
})
]
}
}
```
## Options
### `silent`
Show some runtime log
- Default: `true`
### `root`
Assign root path, it is the value for `` placeholder.
- Type: `string`
### `include`
The included paths for mapping
- Type: `Array`
- Default: `[options.root]`
### `exclude`
The excluded paths for mapping
- Type: `Array`
- Default: `[]`
### `mapper`
absolute filename mapper.
- Type: `(filename, ctx) => string | (filename, ctx, callback) => void | {}`
- Example
```javascript
{
'^/from/(\w+)': '/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, moyuyc95@gmail.com.
## License
MIT - [imcuttle](https://github.com/imcuttle) 🐟