diff --git a/babel-preset/configs/hmr.js b/babel-preset/configs/hmr.js index 9131810eb..d45d4369a 100644 --- a/babel-preset/configs/hmr.js +++ b/babel-preset/configs/hmr.js @@ -18,6 +18,12 @@ module.exports = function(options, filename) { var transform = filename ? './' + path.relative(path.dirname(filename), transformPath) // packager can't handle absolute paths : hmrTransform; + + // Fix the module path to use '/' on Windows. + if (path.sep === '\\') { + transform = transform.replace(/\\/g, '/'); + } + return { plugins: resolvePlugins([ [ diff --git a/packager/react-packager/src/Bundler/index.js b/packager/react-packager/src/Bundler/index.js index 2fd484c0b..30da6417e 100644 --- a/packager/react-packager/src/Bundler/index.js +++ b/packager/react-packager/src/Bundler/index.js @@ -189,23 +189,24 @@ class Bundler { ); } - _hmrURL(prefix, platform, extensionOverride, path) { - const matchingRoot = this._projectRoots.find(root => path.startsWith(root)); + _hmrURL(prefix, platform, extensionOverride, filePath) { + const matchingRoot = this._projectRoots.find(root => filePath.startsWith(root)); if (!matchingRoot) { - throw new Error('No matching project root for ', path); + throw new Error('No matching project root for ', filePath); } - const extensionStart = path.lastIndexOf('.'); - let resource = path.substring( + // Replaces '\' with '/' for Windows paths. + if (path.sep === '\\') { + filePath = filePath.replace(/\\/g, '/'); + } + + const extensionStart = filePath.lastIndexOf('.'); + let resource = filePath.substring( matchingRoot.length, extensionStart !== -1 ? extensionStart : undefined, ); - const extension = extensionStart !== -1 - ? path.substring(extensionStart + 1) - : null; - return ( prefix + resource + '.' + extensionOverride + '?' +