Gathering detailed insights and metrics for simple-mock-webpack-plugin
Gathering detailed insights and metrics for simple-mock-webpack-plugin
npm install simple-mock-webpack-plugin
Typescript
Module System
Node Version
NPM Version
TypeScript (100%)
Total Downloads
553
Last Day
1
Last Week
5
Last Month
12
Last Year
65
6 Commits
2 Watching
1 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
0.0.2
Package Id
simple-mock-webpack-plugin@0.0.2
Unpacked Size
17.81 kB
Size
6.03 kB
File Count
11
NPM Version
6.4.1
Node Version
10.15.2
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
0%
5
Compared to previous week
Last month
1,100%
12
Compared to previous month
Last year
-23.5%
65
Compared to previous year
Binds a local service to your webpack-dev-server
for mocking data.
mockjs
to support data mocking, learn more about nuysoft/MockP.S.: This repo is called
simple-mock-webpack-plugin
, but it isn't a stantardwebpack-plugin
because of its usage. 😂
Yarn
1yarn add -D simple-mock-webpack-plugin
NPM
1npm i -D simple-mock-webpack-plugin
1. Sets devServer.before
in webpack.config.js
1const { buildBefore } = require('simple-mock-webpack-plugin') 2 3module.exports = { 4 devServer: { 5 before: buildBefore() 6 } 7}
2. Create a config file named mock.js
in the same directory
1module.exports = { 2 apis: [ 3 { 4 url: '/test', 5 template: { 6 code: '@integer(100,600)', 7 msg: 'ok' 8 } 9 }, 10 { 11 url: '/test-promise', 12 template: (mock) => { 13 return new Promise((res) => { 14 setTimeout(() => { 15 res(mock({ 16 code: '@integer(100,600)', 17 msg: 'ok' 18 })) 19 }, 3000) 20 }) 21 } 22 }, 23 { 24 url: '/count', 25 template(mock, { state, request, response, Mock }) { 26 state.counter = (state.counter || 0) + 1 27 return { 28 data: state.counter 29 } 30 } 31 }, 32 { 33 url: '/get-count-number', 34 template(mock, { state, request, response, Mock }) { 35 return { 36 count: state.counter || 0 37 } 38 } 39 }, 40 ] 41}
3. Have a try
1const _fetch = url => fetch(url).then(resp => resp.json()).then(console.log) 2 3_fetch('/test') // {code: 264, msg: "ok"} 4_fetch('/count') // {data: 1} 5_fetch('/count') // {data: 2}
Name | Type | Required | Default | Description |
---|---|---|---|---|
configPath | string | No | ./mock.js | The path of config file |
log | boolean | No | true | Whether prints logs |
before | Function | No | null | Customized before |
reloadDelay | number | No | 300 | Dealy of service's reloading |
Example
1module.exports = { 2 devServer: { 3 before: buildBefore({ configPath: path.resolve(__dirname, 'my_mock.js') }) 4 } 5}
Learn more about the configuration at examples.
MockConfig
Name | Type | Required | Default | Description |
---|---|---|---|---|
prefix | string | No | / | The prefix of all APIs |
delay | boolean | No | 0 | Dealy of the reponse for all APIs |
apis | MockAPI[] | Yes | The configuration of APIs |
MockAPI
Name | Type | Required | Default | Description |
---|---|---|---|---|
url | string | Yes | Path relative to the prefix | |
method | string | No | all | The method of API |
template | object | MockAPIHandler | Yes | The tempalte of response. It will be regared as mockjs template if it is an object .(Learn more at Syntax). You can custmize reponse if you set it as a function. |
MockAPIHandler
1(mock: MockjsMock, options: ExtraOptions) => object|Promise<object>
ExtraOptions
Name | Type | Default | Description |
---|---|---|---|
state | object | {} | Temporary states in the service. It will not be affected from config changing |
request | Express.Request | Express Request | |
response | Express.Response | Express Response | |
Mock | Mock.Mockjs | Mock = require('mockjs') |
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 0/6 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-01-20
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