Skip to content

Instantly share code, notes, and snippets.

@eqyiel
Last active November 3, 2017 02:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eqyiel/e3373cdeb2cd7bac76f758f3d1d1e92c to your computer and use it in GitHub Desktop.
Save eqyiel/e3373cdeb2cd7bac76f758f3d1d1e92c to your computer and use it in GitHub Desktop.
How to monkeypatch webpack-dev-server ^2.9.3 for use with react-devtools
/**
* webpack.config.js
*/
const webpack = require('webpack');
const path = require('path');
const { stripIndent } = require('common-tags');
module.exports = (env, { p: production }) => ({
...{
entry: path.resolve(__dirname, './index.js'),
output: {
filename: 'bundle.js',
},
// ... other config
devServer: {
hot: true,
open: true,
before: (_, devServer) => {
devServer.serveMagicHtml = (req, res, next) => {
res.end(
stripIndent`
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<script type="text/javascript" charset="utf-8" src="http://localhost:8097"></script>
</head>
<body>
<script type="text/javascript" charset="utf-8" src="${req.path}.js${req
._parsedUrl.search || ''}"></script>
</body>
</html>`,
);
};
},
openPage: 'webpack-dev-server/bundle',
overlay: {
warnings: true,
errors: true,
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment