mock-service-webpack-plugin

5.0.1 • Public • Published

logo

mock-service-webpack-plugin

A Mock Service Based on Webpack 4/5

Architecture

mechanism

Use Inter-Process Communication in Node.js to handle HTTP Request between Webpack Dev Server and Mock Server:

ipc

Installation

$ npm i mock-service-webpack-plugin

Instruction

Require mock-service-webpack-plugin

const MockServiceWebpackPlugin = require('mock-service-webpack-plugin')

Call the apply method with the webpack mock

myPluginInstance.apply()

Example

Webpack

Modify your webpack.config.js

const MockServiceWebpackPlugin = require('mock-service-webpack-plugin');

const path = require('path');
const fs = require('fs');

module.exports = {
    plugins: [
        new MockServiceWebpackPlugin({
            source: path.resolve(process.cwd(), './src/mock'), // your mock file directory path
            port: 9009 // you wanna a mock service port
        })
    ]
}

Vue Cli

Modify your vue.config.js

if your @vue/cli-service: ~5.0.0

const { defineConfig } = require('@vue/cli-service');
const MockServiceWebpackPlugin = require('mock-service-webpack-plugin');

const path = require('path');
const fs = require('fs');

module.exports = defineConfig({
    configureWebpack: {
        plugins: [
            new MockServiceWebpackPlugin({
                source: path.resolve(process.cwd(), './src/mock'), // your mock file directory path
                port: 9009 // you wanna a mock service port
            })
        ]
    }
})

or in 4.x

const MockServiceWebpackPlugin = require('mock-service-webpack-plugin');

const path = require('path');
const fs = require('fs');

module.exports = {
    configureWebpack: {
        plugins: [
            new MockServiceWebpackPlugin({
                source: path.resolve(process.cwd(), './src/mock'), // your mock file directory path
                port: 9009 // you wanna a mock service port
            })
        ]
    }
}

License

MIT

Copyright (c) 2023-present Victor Lee

Package Sidebar

Install

npm i mock-service-webpack-plugin

Weekly Downloads

1

Version

5.0.1

License

MIT

Unpacked Size

1.6 MB

Total Files

11

Last publish

Collaborators

  • we452366