A easy debug plugin for eruda and vConsole.
npm install local-mock-easyEnglish | 简体中文
local-mock-easy
shell
npm i local-mock-easy
yarn add local-mock-easy
`
##### Using local-mock-easy from CDN
`html
`
$3
#### Plugin for eruda
`js
// #!if ENV === "development"
import eruda from 'eruda'
import { erudaLocalMock } from 'local-mock-easy'
eruda.init()
const localMockplugin = erudaLocalMock(eruda, {})
eruda.add(localMockplugin)
// #!endif
`
#### Plugin for vConsole
`js
// #!if ENV === "development"
import VConsole from 'vconsole'
import { vconsoleLocalMock } from 'local-mock-easy'
const vconsole = new VConsole()
const localMockplugin = vconsoleLocalMock(VConsole, {
key: 'myLocalMock',
state: 0,
entry: 'http://localhost:8080',
fast: 0,
// default agent mode, pleace install local-mock-middleware on nodejs gateway
mode: 'agent',
})
vconsole.addPlugin(localMockplugin)
// #!endif
`
$3
Since the entry file of 'devServer' is loaded in the domain name, you need to configure cross-origin and configure publicPath to load local static resources.
`json
{
"devServer": {
"publicPath": "http://localhost:8080",
"port": 8080,
"headers": {
"Access-Control-Allow-Origin": "*"
}
}
}
`
$3
- The cellular network needs to be on the same LAN as the localhost.
- publicPath and proxy change to http://{ip}:{port}, such as: http://192.168.1.10:8080
Options API
| params | desc | type | default |
| :-- | :-- | :-- | :-- |
| state | plugin open state | number | 0 |
| entry | the local entry | string | http://localhost:8080 |
| key | the query params name in url.
http://example.com?{key}={entry} | string | localMock |
| fast | whether to show fast button | number | 0 |
| mode | both static and gateway scenarios are supported | static or agent | agent` |