Gathering detailed insights and metrics for mock-webpack-plugin
Gathering detailed insights and metrics for mock-webpack-plugin
npm install mock-webpack-plugin
Typescript
Module System
Node Version
NPM Version
71.6
Supply Chain
92.9
Quality
73
Maintenance
50
Vulnerability
99.6
License
JavaScript (100%)
Total Downloads
19,933
Last Day
31
Last Week
131
Last Month
674
Last Year
6,806
24 Stars
70 Commits
6 Forks
4 Watching
32 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
3.0.0
Package Id
mock-webpack-plugin@3.0.0
Unpacked Size
233.85 kB
Size
61.79 kB
File Count
27
NPM Version
6.13.4
Node Version
10.18.1
Cumulative downloads
Total Downloads
Last day
-35.4%
31
Compared to previous day
Last week
-35.1%
131
Compared to previous week
Last month
-0.4%
674
Compared to previous month
Last year
515.4%
6,806
Compared to previous year
6
A webpack plugin that starts a json mock server
For the front and back of the development of the project, most of the situation is the first agreed interface format, front-end use of local mock data to develop. Webpack-dev-server provides proxy configuration, we can be in the development of the interface agent to the local service. Mock data using the json file can be the most convenient development, but in the webpack-dev-server 1.6 after the version does not support the interface proxy to json file. The webpack-dev-server proxy uses http-proxy-middleware, which issue explains why.
So in the development process we need to build the server, to point to the interface JSON file. The function of the plug-in is to serve a courier service to these interfaces, and according to the configuration point to the corresponding JSON file.
npm install --save-dev webpack mock-webpack-plugin
if you are using webpack@2 or webpack@3, you can install the mock-webpack-plugin@2
npm install --save-dev webpack mock-webpack-plugin@2
webpack config
1{ 2 // webpack plugins config 3 plugins: [ 4 new MockWebpackPlugin({ 5 config: mockConfig, 6 port: 5000 7 }) 8 ], 9 devServer: { 10 // As MockWebpackPlugin only starts a mock server, 11 // you need to config the devServer.proxy 12 // to make your app access the mock data through the same origin 13 proxy: { 14 'api': 'http://localhost:3000' 15 } 16 } 17}
mockConfig
1 2const path = require('path'); 3 4const config = { 5 '/api/json/data': { 6 data: { 7 result: 'mocked' 8 } 9 }, 10 '/api/json/path': { 11 path: path.join(__dirname, './json/result.json') 12 }, 13 '/api/mockjs/data': { 14 data: { 15 'result|3': '*' 16 } 17 }, 18 '/api/mockjs/path': { 19 path: path.join(__dirname, './json/mockjs.json') 20 } 21}; 22 23module.exports = config;
options.port
port for mock server.Can not be the same as webpack dev server's port.Because the plugin start a new server besides webpack dev server.
options.config
is a object of mock data config. The key is the route of your api. The data can be offered by 2 ways. Inline mock data and a path to the data. You can use json data and Mock.js template to provide your mock data.
You can find a demo here.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
77 existing vulnerabilities detected
Details
Score
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