New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mockoon-webpack-plugin

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mockoon-webpack-plugin

A Webpack plugin based on Mockoon CLI.

  • 2.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
80
increased by40.35%
Maintainers
1
Weekly downloads
 
Created
Source

mockoon-webpack-plugin

GitHub license nodejs-version

A Webpack plugin based on Mockoon CLI (https://mockoon.com/) that simplifies the creation mock(s) server to give APIs on localhost and stop it when close webpack-dev-server.

Installation

npm install --save-dev mockoon-webpack-plugin

or

yarn add --dev mockoon-webpack-plugin

Usage

To create 1 mock server:

// webpack.config.js
const { MockoonWebpackPlugin } = require("mockoon-webpack-plugin");

module.exports = {
    ...
    plugins: [
        ...
        new MockoonWebpackPlugin({
            data: "https://url/to/mockoon/file"
        });
    ]
};

or, to create 2 mock servers using 2 Mockoon's files:

// webpack.config.js
const { MockoonWebpackPlugin } = require("mockoon-webpack-plugin");

module.exports = {
    ...
    plugins: [
        ...
        new MockoonWebpackPlugin([{
            data: "./relative/path/to/mockoon/file",
            port: 1025
        }, {
            data: "/absolute/path/to/mockoon/local/file"
        }]);
    ]
};

or, to create 2 mock servers using a Mockoon's file and the custom object configuration:

// webpack.config.js
const { MockoonWebpackPlugin } = require("mockoon-webpack-plugin");

module.exports = {
    ...
    plugins: [
        ...
        new MockoonWebpackPlugin([{
            data: "./relative/path/to/mockoon/local/file",
            port: 1025
        }, {
            data: {
                routes: [{
                    method: "GET";
                    endpoint: "/getUsers";
                    responses: [{
                        body: JSON.stringify([{
                            id: 1,
                            name: "John",
                            surname: "Doe",
                        }, {
                            id: 2,
                            name: "Ian",
                            surname: "Moore"
                        }])
                        statusCode: 200
                    }]
                }]
            },
            port: 5055
        }]);
    ]
};

Options

  • data (required), you can specify the local file path or an url of a Mockoon file, or an object like this:
    data: {
        routes: [{
            method: string,
            endpoint: string,
            responses: [{
                body: string,
    
                latency: (optional) string,
    
                statusCode: number,
                
                headers: (optional) [{
                    key: string,
                    value: string
                }],
    
                rules: (optional) [{
                    target: string,
                    modifier: string,
                    value: string,
                    operator: string
                }]
            }]
        }],
        cors: boolean,
    
        headers: (optional) [{
            key: string,
            value: string
        }],
    }
    
  • pname (optional), process name (if not specified the plugin will create a unique name)
  • port (optional), evironment's port (if not specified the plugin will search a free port)

Example Webpack Config

See examples folder.

Keywords

FAQs

Package last updated on 27 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc