Skip to content

Instantly share code, notes, and snippets.

@timonweb
Created February 6, 2019 11:07
Show Gist options
  • Save timonweb/597d501c38e641973388061875bc4cb8 to your computer and use it in GitHub Desktop.
Save timonweb/597d501c38e641973388061875bc4cb8 to your computer and use it in GitHub Desktop.
const fs = require("fs");
const pathClient = "./node_modules/react-dev-utils/webpackHotDevClient.js";
fs.writeFileSync(
pathClient,
fs
.readFileSync(pathClient)
.toString()
.replace(
`var connection = new SockJS(
url.format({
protocol: window.location.protocol,
hostname: window.location.hostname,
port: window.location.port,
// Hardcoded in WebpackDevServer
pathname: '/sockjs-node',
})
);`,
`
var scriptUrl = document.currentScript
? url.parse(document.currentScript.src)
: window.location;
var connection = new SockJS(
url.format({
protocol: scriptUrl.protocol,
hostname: scriptUrl.hostname,
port: scriptUrl.port,
// Hardcoded in WebpackDevServer
pathname: '/sockjs-node',
})
);`
)
);
const pathConfig = "./node_modules/react-scripts/config/webpackDevServer.config.js";
fs.writeFileSync(
pathConfig,
fs
.readFileSync(pathConfig)
.toString()
.replace(
`const publicPath = '/';`,
`const publicPath = process.env.PUBLIC_PATH || '/';`
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment