Fix require on network share path (#12282)

* first pass at server/network require fix

* refactor for clarity
This commit is contained in:
Shelley Vohr 2018-03-15 11:45:13 +09:00 committed by Samuel Attard
parent 1f8de33e75
commit 9aeb61181a

View file

@ -141,7 +141,18 @@ if (nodeIntegration === 'true') {
// Set the __filename to the path of html file if it is file: protocol.
if (window.location.protocol === 'file:') {
var pathname = process.platform === 'win32' && window.location.pathname[0] === '/' ? window.location.pathname.substr(1) : window.location.pathname
const location = window.location
let pathname = location.pathname
if (process.platform === 'win32') {
if (pathname[0] === '/') pathname = pathname.substr(1)
const isWindowsNetworkSharePath = location.hostname.length > 0 && globalPaths[0].startsWith('\\')
if (isWindowsNetworkSharePath) {
pathname = `//${location.host}/${pathname}`
}
}
global.__filename = path.normalize(decodeURIComponent(pathname))
global.__dirname = path.dirname(global.__filename)