Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

absolute-module-mapper-plugin

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

absolute-module-mapper-plugin

The plugin on enhanced-resolver to map module path

  • 1.2.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

absolute-module-mapper-plugin

Build status Test coverage NPM version NPM Downloads Prettier Conventional Commits

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 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 🐟

Keywords

FAQs

Package last updated on 13 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc