https://github.com/imcuttle/module-mock-plugin
The plugin on enhanced-resolver for easy mock
https://github.com/imcuttle/module-mock-plugin
mock module-mapper override overwrite webpack
Last synced: about 6 hours ago
JSON representation
The plugin on enhanced-resolver for easy mock
- Host: GitHub
- URL: https://github.com/imcuttle/module-mock-plugin
- Owner: imcuttle
- License: mit
- Created: 2020-02-13T09:33:40.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T07:15:19.000Z (about 3 years ago)
- Last Synced: 2025-09-17T12:05:16.082Z (4 months ago)
- Topics: mock, module-mapper, override, overwrite, webpack
- Language: JavaScript
- Size: 1.11 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: License
Awesome Lists containing this project
README
# module-mock-plugin
[](https://travis-ci.org/imcuttle/module-mock-plugin)
[](https://codecov.io/github/imcuttle/module-mock-plugin?branch=master)
[](https://www.npmjs.com/package/module-mock-plugin)
[](https://www.npmjs.com/package/module-mock-plugin)
[](https://prettier.io/)
[](https://conventionalcommits.org)
> 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.

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.
```text
src/
__mock/
react/ # custom react
node_modules/
react/
```
- `src/__mock/react/index.js`
```javascript
import React from 'react'
export * from 'react'
export function createElement(type, props, children) {
// ... custom code
}
```
## Installation
```bash
npm install module-mock-plugin
# or use yarn
yarn add module-mock-plugin
```
## Use in webpack
```javascript
const ModuleMockPlugin = require('module-mock-plugin')
const webpackConfig = {
resolve: {
plugins: [new ModuleMockPlugin()]
}
}
```
## Options
Extends the options from [absolute-module-mapper-plugin](https://github.com/imcuttle/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`
- Default: `[/^((?!\/node_modules\/).)*$/]`
#### `exclude`
The excluded paths for mapping
- Type: `Array`
- Default: `[]`
## Related
- [absolute-module-mapper-plugin](https://github.com/imcuttle/absolute-module-mapper-plugin) - The plugin on enhanced-resolver to map module path.
## 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) 🐟