absolute-module-mapper-plugin
v1.3.1
Published
The plugin on enhanced-resolver to map module path
Downloads
15
Maintainers
Readme
absolute-module-mapper-plugin
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.
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
npm install absolute-module-mapper-plugin
# or use yarn
yarn add absolute-module-mapper-plugin
Usage in webpack
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
{
'^<root>/from/(\w+)': '<root>/to/$1'
}
requestMapper
request mapper.
- Type:
(request, ctx) => string | (request, ctx, callback) => void | {}
- Example
{
'^./a.js$': './b.js'
}
Contributing
- Fork it!
- Create your new branch:
git checkout -b feature-new
orgit 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)'
orgit 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, [email protected].
License
MIT - imcuttle 🐟