@reactseed/devserver
Override webpack devServer configuration for create-react-app 2.0 order to support mockServer.
How to install
This project relies on react-app-rewired
、customize-cra
. You'll need to install that in order for @reactseed/devserver
to work.
yarn add customize-cra react-app-rewired @reactseed/devserver --dev
Usage
Configure customize-cra
/* config-overrides.js */
const { overrideDevServer } = require('customize-cra');
const devServer = require('@reactseed/devserver');
module.exports = {
devServer: overrideDevServer(devServer),
};
Conventional Mock file
Conventions All files in the /mock
folder are mock files except files whose file name starts with _
.
.
├── mock
├── _constant.js
└── app.js
└── src
Write Mock files
/* _constant.js */
module.exports = {
apiPrefix: '/api',
};
/* app.js */
const { apiPrefix } = require('./_constant');
const packageJSON = require('../package.json');
module.exports = {
[`GET ${apiPrefix}/app`]: packageJSON,
};
Visit /api/app
to get a response.