@pmmmwh/react-refresh-webpack-plugin
Advanced tools
Comparing version 0.5.1 to 0.5.2
@@ -21,15 +21,48 @@ const querystring = require('querystring'); | ||
if (devServer) { | ||
const { sockHost, sockPath, sockPort, host, path, port, https, http2 } = devServer; | ||
const { client, https, http2, sockHost, sockPath, sockPort } = devServer; | ||
let { host, path, port } = devServer; | ||
(sockHost || host) && (resourceQuery.sockHost = sockHost ? sockHost : host); | ||
(sockPath || path) && (resourceQuery.sockPath = sockPath ? sockPath : path); | ||
(sockPort || port) && (resourceQuery.sockPort = sockPort ? sockPort : port); | ||
resourceQuery.sockProtocol = https || http2 ? 'https' : 'http'; | ||
let protocol = https || http2 ? 'https' : 'http'; | ||
if (sockHost) host = sockHost; | ||
if (sockPath) path = sockPath; | ||
if (sockPort) port = sockPort; | ||
if (client && client.webSocketURL != null) { | ||
let parsedUrl = client.webSocketURL; | ||
if (typeof parsedUrl === 'string') parsedUrl = new URL(parsedUrl); | ||
let auth; | ||
if (parsedUrl.username) { | ||
auth = parsedUrl.username; | ||
if (parsedUrl.password) { | ||
auth += ':' + parsedUrl.password; | ||
} | ||
} | ||
if (parsedUrl.hostname != null) { | ||
host = [auth != null && auth, parsedUrl.hostname].filter(Boolean).join('@'); | ||
} | ||
if (parsedUrl.pathname != null) { | ||
path = parsedUrl.pathname; | ||
} | ||
if (parsedUrl.port != null) { | ||
port = String(parsedUrl.port) !== '0' ? parsedUrl.port : undefined; | ||
} | ||
if (parsedUrl.protocol != null) { | ||
protocol = parsedUrl.protocol !== 'auto' ? parsedUrl.protocol.replace(':', '') : 'ws'; | ||
} | ||
} | ||
if (host) resourceQuery.sockHost = host; | ||
if (path) resourceQuery.sockPath = path; | ||
if (port) resourceQuery.sockPort = port; | ||
resourceQuery.sockProtocol = protocol; | ||
} | ||
if (options.overlay) { | ||
options.overlay.sockHost && (resourceQuery.sockHost = options.overlay.sockHost); | ||
options.overlay.sockPath && (resourceQuery.sockPath = options.overlay.sockPath); | ||
options.overlay.sockPort && (resourceQuery.sockPort = options.overlay.sockPort); | ||
options.overlay.sockProtocol && (resourceQuery.sockProtocol = options.overlay.sockProtocol); | ||
const { sockHost, sockPath, sockPort, sockProtocol } = options.overlay; | ||
if (sockHost) resourceQuery.sockHost = sockHost; | ||
if (sockPath) resourceQuery.sockPath = sockPath; | ||
if (sockPort) resourceQuery.sockPort = sockPort; | ||
if (sockProtocol) resourceQuery.sockProtocol = sockProtocol; | ||
} | ||
@@ -36,0 +69,0 @@ |
@@ -30,41 +30,40 @@ const { getRefreshGlobalScope } = require('../globals'); | ||
} originalFactory = options.factory;`, | ||
`options.factory = ${runtimeTemplate.basicFunction( | ||
'moduleObject, moduleExports, webpackRequire', | ||
[ | ||
`${refreshGlobal}.setup(options.id);`, | ||
'try {', | ||
webpack.Template.indent( | ||
'originalFactory.call(this, moduleObject, moduleExports, webpackRequire);' | ||
), | ||
'} finally {', | ||
`options.factory = function (moduleObject, moduleExports, webpackRequire) {`, | ||
webpack.Template.indent([ | ||
`${refreshGlobal}.setup(options.id);`, | ||
'try {', | ||
webpack.Template.indent( | ||
'originalFactory.call(this, moduleObject, moduleExports, webpackRequire);' | ||
), | ||
'} finally {', | ||
webpack.Template.indent([ | ||
`if (typeof Promise !== 'undefined' && moduleObject.exports instanceof Promise) {`, | ||
webpack.Template.indent([ | ||
`if (typeof Promise !== 'undefined' && moduleObject.exports instanceof Promise) {`, | ||
// The exports of the module are re-assigned - | ||
// this ensures anything coming after us would wait for `cleanup` to fire. | ||
// This is particularly important because `cleanup` restores the refresh global, | ||
// maintaining consistency for mutable variables like `moduleId`. | ||
// This `.then` clause is a ponyfill of the `Promise.finally` API - | ||
// it is only part of the spec after ES2018, | ||
// but Webpack's top level await implementation support engines down to ES2015. | ||
'options.module.exports = options.module.exports.then(', | ||
webpack.Template.indent([ | ||
// The exports of the module are re-assigned - | ||
// this ensures anything coming after us would wait for `cleanup` to fire. | ||
// This is particularly important because `cleanup` restores the refresh global, | ||
// maintaining consistency for mutable variables like `moduleId`. | ||
// This `.then` clause is a ponyfill of the `Promise.finally` API - | ||
// it is only part of the spec after ES2018, | ||
// but Webpack's top level await implementation support engines down to ES2015. | ||
'options.module.exports = options.module.exports.then(', | ||
webpack.Template.indent([ | ||
`${runtimeTemplate.basicFunction('result', [ | ||
`${refreshGlobal}.cleanup(options.id);`, | ||
'return result;', | ||
])},`, | ||
runtimeTemplate.basicFunction('reason', [ | ||
`${refreshGlobal}.cleanup(options.id);`, | ||
'return Promise.reject(reason);', | ||
]), | ||
`${runtimeTemplate.basicFunction('result', [ | ||
`${refreshGlobal}.cleanup(options.id);`, | ||
'return result;', | ||
])},`, | ||
runtimeTemplate.basicFunction('reason', [ | ||
`${refreshGlobal}.cleanup(options.id);`, | ||
'return Promise.reject(reason);', | ||
]), | ||
`);`, | ||
]), | ||
'} else {', | ||
webpack.Template.indent(`${refreshGlobal}.cleanup(options.id)`), | ||
'}', | ||
`);`, | ||
]), | ||
'} else {', | ||
webpack.Template.indent(`${refreshGlobal}.cleanup(options.id)`), | ||
'}', | ||
] | ||
)}`, | ||
]), | ||
'}', | ||
]), | ||
`};`, | ||
] | ||
@@ -71,0 +70,0 @@ )})`, |
{ | ||
"name": "@pmmmwh/react-refresh-webpack-plugin", | ||
"version": "0.5.1", | ||
"version": "0.5.2", | ||
"description": "An **EXPERIMENTAL** Webpack plugin to enable \"Fast Refresh\" (also previously known as _Hot Reloading_) for React components.", | ||
@@ -99,3 +99,4 @@ "keywords": [ | ||
"puppeteer": "^9.1.1", | ||
"react-refresh": "^0.10.0", | ||
"react-refresh": "^0.11.0", | ||
"semver": "^7.3.5", | ||
"sourcemap-validator": "^2.1.0", | ||
@@ -107,3 +108,4 @@ "type-fest": "^1.4.0", | ||
"webpack-cli.legacy": "npm:webpack-cli@3.x", | ||
"webpack-dev-server": "^3.11.2", | ||
"webpack-dev-server": "^4.2.1", | ||
"webpack-dev-server.legacy": "npm:webpack-dev-server@3.x", | ||
"webpack-hot-middleware": "^2.25.0", | ||
@@ -117,3 +119,3 @@ "webpack-plugin-serve": "^1.4.1", | ||
"@types/webpack": "4.x || 5.x", | ||
"react-refresh": "^0.10.0", | ||
"react-refresh": ">=0.10.0 <1.0.0", | ||
"sockjs-client": "^1.4.0", | ||
@@ -120,0 +122,0 @@ "type-fest": ">=0.17.0 <3.0.0", |
@@ -262,3 +262,3 @@ # React Refresh Webpack Plugin | ||
Ensure your `@swc/core` version is at least `1.2.52`. | ||
Ensure your `@swc/core` version is at least `1.2.86`. | ||
It is also recommended to use `swc-loader` version `0.1.13` or above. | ||
@@ -265,0 +265,0 @@ |
3071
62
2
2
2
3
126641
45
58