From be992c90e98afcbc3e7b1b1a8a163bb2dbd51ac6 Mon Sep 17 00:00:00 2001 From: Amjad Masad Date: Mon, 16 Mar 2015 15:15:07 -0700 Subject: [PATCH] [react-packager] small fixes to image loader --- .../haste/DependencyGraph/index.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/react-packager/src/DependencyResolver/haste/DependencyGraph/index.js b/react-packager/src/DependencyResolver/haste/DependencyGraph/index.js index 122701d5..a7bf1f53 100644 --- a/react-packager/src/DependencyResolver/haste/DependencyGraph/index.js +++ b/react-packager/src/DependencyResolver/haste/DependencyGraph/index.js @@ -134,13 +134,17 @@ DependecyGraph.prototype.resolveDependency = function( fromModule, depModuleId ) { - // Process asset requires. - var assetMatch = depModuleId.match(/^image!(.+)/); - if (assetMatch && assetMatch[1]) { - if (!this._assetMap[assetMatch[1]]) { - throw new Error('Cannot find asset: ' + assetMatch[1]); + + if (this._assetMap != null) { + // Process asset requires. + var assetMatch = depModuleId.match(/^image!(.+)/); + if (assetMatch && assetMatch[1]) { + if (!this._assetMap[assetMatch[1]]) { + console.warn('Cannot find asset: ' + assetMatch[1]); + return null; + } + return this._assetMap[assetMatch[1]]; } - return this._assetMap[assetMatch[1]]; } var packageJson, modulePath, dep; @@ -577,7 +581,8 @@ function buildAssetMap(roots, exts) { } else { var ext = path.extname(file).replace(/^\./, ''); if (exts.indexOf(ext) !== -1) { - var assetName = path.basename(file, '.' + ext); + var assetName = path.basename(file, '.' + ext) + .replace(/@[\d\.]+x/, ''); if (map[assetName] != null) { debug('Conflcting assets', assetName); }