fix hot reload next 12 https://github.com/HaNdTriX/next-electron-server/issues/7#issuecomment-1143371567
This commit is contained in:
parent
c3c99e0970
commit
239e243ac3
|
@ -1,6 +1,6 @@
|
||||||
import { Readable } from 'stream';
|
import { Readable } from 'stream';
|
||||||
import * as fs from 'promise-fs';
|
import * as fs from 'promise-fs';
|
||||||
import * as electron from 'electron';
|
import { webFrame, ipcRenderer } from 'electron';
|
||||||
import {
|
import {
|
||||||
getElectronFile,
|
getElectronFile,
|
||||||
getPendingUploads,
|
getPendingUploads,
|
||||||
|
@ -13,7 +13,23 @@ import { ElectronFile } from './types';
|
||||||
import { getEncryptionKey, setEncryptionKey } from './utils/safeStorage';
|
import { getEncryptionKey, setEncryptionKey } from './utils/safeStorage';
|
||||||
import { clearElectronStore } from './utils/electronStore';
|
import { clearElectronStore } from './utils/electronStore';
|
||||||
|
|
||||||
const { ipcRenderer } = electron;
|
// Patch the global WebSocket constructor to use the correct DevServer url
|
||||||
|
const fixHotReloadNext12 = () => {
|
||||||
|
webFrame.executeJavaScript(`Object.defineProperty(globalThis, 'WebSocket', {
|
||||||
|
value: new Proxy(WebSocket, {
|
||||||
|
construct: (Target, [url, protocols]) => {
|
||||||
|
if (url.endsWith('/_next/webpack-hmr')) {
|
||||||
|
// Fix the Next.js hmr client url
|
||||||
|
return new Target("ws://localhost:3000/_next/webpack-hmr", protocols)
|
||||||
|
} else {
|
||||||
|
return new Target(url, protocols)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});`);
|
||||||
|
};
|
||||||
|
|
||||||
|
fixHotReloadNext12();
|
||||||
|
|
||||||
const responseToReadable = (fileStream: any) => {
|
const responseToReadable = (fileStream: any) => {
|
||||||
const reader = fileStream.getReader();
|
const reader = fileStream.getReader();
|
||||||
|
|
Loading…
Reference in a new issue