All Projects → MarxJiao → mock-webpack-plugin

MarxJiao / mock-webpack-plugin

Licence: MIT license
A webpack plugin that starts a json mock server

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to mock-webpack-plugin

Mockoon
Mockoon is the easiest and quickest way to run mock APIs locally. No remote deployment, no account required, open source.
Stars: ✭ 3,448 (+16319.05%)
Mutual labels:  mock-server, mock-data
platypus
Very simple and customizable mock/echo server
Stars: ✭ 15 (-28.57%)
Mutual labels:  mock-server
Webpack Shell Plugin
Run shell commands either before or after webpack builds
Stars: ✭ 250 (+1090.48%)
Mutual labels:  webpack-plugin
webpack-omit-js-for-css-plugin
This plugin will omit bundled JS files for dependencies that are exclusively CSS, which become obsolete once mini-css-extract-plugin extracts inlined CSS into its own .css file
Stars: ✭ 14 (-33.33%)
Mutual labels:  webpack-plugin
webpack-bugsnag-plugins
Webpack plugins for common Bugsnag actions.
Stars: ✭ 29 (+38.1%)
Mutual labels:  webpack-plugin
asset-map-webpack-plugin
Webpack plugin that creates a map of assets to public url slug for server agnostic usage.
Stars: ✭ 14 (-33.33%)
Mutual labels:  webpack-plugin
Copy Webpack Plugin
Copy files and directories with webpack
Stars: ✭ 2,679 (+12657.14%)
Mutual labels:  webpack-plugin
webpack-demos
webpack小练习
Stars: ✭ 17 (-19.05%)
Mutual labels:  webpack-plugin
image-minimizer-webpack-plugin
Webpack loader and plugin to compress images using imagemin
Stars: ✭ 180 (+757.14%)
Mutual labels:  webpack-plugin
sitemap-webpack-plugin
Webpack plugin to generate a sitemap.
Stars: ✭ 72 (+242.86%)
Mutual labels:  webpack-plugin
fe-dev-server
FE Dev Server target to help frontend web developers create view template, styles and js easily.
Stars: ✭ 30 (+42.86%)
Mutual labels:  mock-data
webpack-extract-translation-keys
This plugin extracts translation keys for applications requiring runtime translations
Stars: ✭ 35 (+66.67%)
Mutual labels:  webpack-plugin
pxtorem-webpack-plugin
A webpack plugin for generating rem for stylesheet and inject auto calculate scripts.
Stars: ✭ 24 (+14.29%)
Mutual labels:  webpack-plugin
nunjucks-webpack-plugin
A webpack plugin for nunjucks.
Stars: ✭ 27 (+28.57%)
Mutual labels:  webpack-plugin
del-webpack-plugin
A file plugin help you remove old files after webpack (v5) bundling
Stars: ✭ 43 (+104.76%)
Mutual labels:  webpack-plugin
Webpack Messages
Beautifully format Webpack messages throughout your bundle lifecycle(s)!
Stars: ✭ 238 (+1033.33%)
Mutual labels:  webpack-plugin
smockin
Dynamic API, S3 & Mail mocking for web, mobile & microservice development.
Stars: ✭ 74 (+252.38%)
Mutual labels:  mock-server
eruda-webpack-plugin
A webpack plugin of eruda to help you develop mobile app
Stars: ✭ 56 (+166.67%)
Mutual labels:  webpack-plugin
qn-webpack
Qiniu webpack plugin (七牛 Webpack 插件)
Stars: ✭ 39 (+85.71%)
Mutual labels:  webpack-plugin
crx-webpack-plugin
A webpack plugin to package chrome extensions (crx) post build
Stars: ✭ 21 (+0%)
Mutual labels:  webpack-plugin

MockWebpackPlugin

Node.js CI

中文readme

A webpack plugin that starts a json mock server

What problem does this plugin solve

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.

Use

Install

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

Config

webpack config

{
    // webpack plugins config
    plugins: [
        new MockWebpackPlugin({
            config: mockConfig,
            port: 5000
        })
    ],
    devServer: {
        // As MockWebpackPlugin only starts a mock server,
        // you need to config the devServer.proxy
        // to make your app access the mock data through the same origin
        proxy: {
            'api': 'http://localhost:3000'
        }
    }
}

mockConfig

const path = require('path');

const config = {
    '/api/json/data': {
        data: {
            result: 'mocked'
        }
    },
    '/api/json/path': {
        path: path.join(__dirname, './json/result.json')
    },
    '/api/mockjs/data': {
        data: {
            'result|3': '*'
        }
    },
    '/api/mockjs/path': {
        path: path.join(__dirname, './json/mockjs.json')
    }
};

module.exports = config;

Options

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.

Demo

You can find a demo here.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].