Installations
npm install happy-mock-webpack-plugin
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
8.11.3
NPM Version
5.6.0
Score
69.6
Supply Chain
98.2
Quality
75.2
Maintenance
100
Vulnerability
99.6
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
JerryYuanJ
Download Statistics
Total Downloads
962
Last Day
5
Last Week
14
Last Month
22
Last Year
111
GitHub Statistics
5 Commits
2 Watching
1 Branches
1 Contributors
Bundle Size
11.48 kB
Minified
5.01 kB
Minified + Gzipped
Package Meta Information
Latest Version
0.0.14
Package Id
happy-mock-webpack-plugin@0.0.14
Unpacked Size
12.53 kB
Size
5.63 kB
File Count
14
NPM Version
5.6.0
Node Version
8.11.3
Total Downloads
Cumulative downloads
Total Downloads
962
Last day
0%
5
Compared to previous day
Last week
0%
14
Compared to previous week
Last month
1,000%
22
Compared to previous month
Last year
-17.8%
111
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
Dev Dependencies
3
Happy-Mock-Webpack--Plugin
This plugin provides a simple way to mock your data via webpack and webapck-dev-server. You can easily mock your own data with just a little configuration.
Note that currently this plugin only supports
GET
method.
Install
1npm install happy-mock-webpack-plugin
Usage
In webpack config file, add this plugin instance:
1const HappyMockMockPlugin = require('happy-mock-webpack-plugin') 2const path = require('path') 3 4module.exports = { 5 // other configs 6 plugins: [ 7 // other plugins... 8 new HappyMockMockPlugin({ 9 root: path.resolve(__dirname, 'mock'), 10 lazy: true, 11 autoRefresh: true 12 }) 13 ] 14}
Mock files
directory example:
- src
- app.js
- mock
- user
- profile.json
- orders.js
- menu.js
The directory path is the request url, for example, if you use axios
, axios.get('/user/profile')
will lead you to /mock/user/profile.json
. There're some mock examples
- /mock/user/orders.js
This file exports a function, it takes request
and response
as args, these two are from webpack-dev-server
which are express
request and response objects. You can return different content via
different request params.
1module.exports = (request, response) => { 2 // handle request ... 3 // modify response ... 4 return { 5 data: [] 6 } 7}
- /mock/user/profile.json
1{ 2 "name": "John Doe" 3} 4
- /mock/menu.js
1module.exports = { 2 items: [], 3 from: 'xx' 4} 5
Other files will be returned as it is.
Configurations
-
root
String
The directory that you want to put your mock files to. It must be an absolute path
-
lazy
Boolean
If it's true, the file will be loaded only when there's request to it. In this case, the request takes longer but app starts faster than the other case.
If it's false, the app will get all mock files and cache it, so the app starts slower, but the request is faster via the cache.
-
autoRefresh
Boolean
If you set it to
true
, every time you change your mock files, the browser will automatically refresh to make sure you can get the lateset data. If it'sfalse
, you need to refresh the browser by yourself to make it.Note: this field works only when
lazy=true
, otherwise the cache will take priority and you need to restart the app to get the updated mock files.
LICENSE
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 0/5 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
3
/10
Last Scanned on 2025-02-03
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More