We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
在 webpack-dev-server 的 before 方法中,使用 webpack-api-mocker 插件拦截了请求,读取本地的 mock 数据(JSON文件)返回
// webpack.dev.conf.js const apiMocker = require('webpack-api-mocker'); require('./mock-generator.js')(); devServer: { before(app) { apiMocker(app, path.resolve('./mock/index.js')); } } // mock/index.js const fs = require('fs'); function fromJSONFile(filepath) { return (req, res) => { const data = fs.readFileSync('mock' + filepath).toString(); const json = JSON.parse(data); return res.json(json); }; }; const proxy = { 'GET /aaa/bbb': fromJSONFile('/aaa/bbb.json'), 'GET /aaa/ccc': fromJSONFile('/aaa/ccc.json') }; module.exports = proxy;
The text was updated successfully, but these errors were encountered:
No branches or pull requests
本地mock处理
在 webpack-dev-server 的 before 方法中,使用 webpack-api-mocker 插件拦截了请求,读取本地的 mock 数据(JSON文件)返回
The text was updated successfully, but these errors were encountered: