a webpack plugin for mocking data
npm install webpack-mock-simple> 基于 mockjs-lite 的 webpack 插件
```
npm i webpack-mock-simple --save-dev
(一般是)webpack.config.js 文件中
``
module.exports.plugins = (module.exports.plugins || []).concat([
// .... 其他插件
new myMock({
path: path.join(__dirname, './mock/index.js'), // mock 管理模块地址,如果不存在会自动创建
port: 3000 // mock 服务器端口,
isInject: true // 是否拦截,默认为 true
})
])
运行 npm run start 或者 npm run dev
增加 testApi.js 文件
``
module.exports = {
'list|1-10': [{
'id|+1': 1
}]
}
并在 mock/index.js 中引入
`
const testApi = require('./testApi');
const getApis = () => {
return {
testApi
}
}
module.exports = getApis;
`
重新启动项目,访问 http://localhost:3000/testApi,查看是否生效。
> 目前仅以 getApis` 返回值的 key 值做 url,value 做 response ,扩展性不好。理论上可以引入 function 来实现动态 mock,计划未来添加。