module-mock-plugin
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

module-mock-plugin

Build status Test coverage NPM version NPM Downloads Prettier Conventional Commits

The plugin on enhanced-resolver for easy mock

Why use it?

One day your project (using React) needs to change the browser's default hovering title behavior as a whole. 1L5qn1.png

This is a lot of work, so the implementation of small modifications is mock react module, so that the place where react is imported in the project points to our custom react module.

src/
    __mock/
        react/ # custom react
node_modules/
    react/
  • src/__mock/react/index.js
import React from 'react'
export * from 'react'
 
export function createElement(type, props, children) {
  // ... custom code
}

Installation

npm install module-mock-plugin
# or use yarn 
yarn add module-mock-plugin

Use in webpack

const ModuleMockPlugin = require('module-mock-plugin')
 
const webpackConfig = {
  resolve: {
    plugins: [new ModuleMockPlugin()]
  }
}

Options

Extends the options from absolute-module-mapper-plugin

mockFilePath

The path of mock directory, it could be inferred as the closest file from origin file, or assigning special file path by absolute path.

  • Type: string
  • Default: __mocks

include

The included paths for mapping

  • Type: Array<string|Function|RegExp>
  • Default: [/^((?!\/node_modules\/).)*$/]

exclude

The excluded paths for mapping

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

Related

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 🐟

Package Sidebar

Install

npm i module-mock-plugin

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

17.9 kB

Total Files

22

Last publish

Collaborators

  • moyuyc