Giter Site home page Giter Site logo

module-mock-plugin's Introduction

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, [email protected].

License

MIT - imcuttle ๐ŸŸ

module-mock-plugin's People

Contributors

imcuttle avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.