[react-packager] Add assetRoots option

This commit is contained in:
Amjad Masad 2015-03-18 19:13:30 -07:00
parent 8a1b71c287
commit ace7e3613f
2 changed files with 6 additions and 2 deletions

View File

@ -45,6 +45,10 @@ if (options.root) {
} }
} }
if (!options.assetRoots) {
options.assetRoots = [path.resolve(__dirname, '..')];
}
console.log('\n' + console.log('\n' +
' ===============================================================\n' + ' ===============================================================\n' +
' | Running packager on port ' + options.port + '. \n' + ' | Running packager on port ' + options.port + '. \n' +
@ -97,6 +101,7 @@ function getAppMiddleware(options) {
blacklistRE: blacklist(false), blacklistRE: blacklist(false),
cacheVersion: '2', cacheVersion: '2',
transformModulePath: require.resolve('./transformer.js'), transformModulePath: require.resolve('./transformer.js'),
assetRoots: options.assetRoots,
}); });
} }

View File

@ -134,13 +134,12 @@ DependecyGraph.prototype.resolveDependency = function(
fromModule, fromModule,
depModuleId depModuleId
) { ) {
if (this._assetMap != null) { if (this._assetMap != null) {
// Process asset requires. // Process asset requires.
var assetMatch = depModuleId.match(/^image!(.+)/); var assetMatch = depModuleId.match(/^image!(.+)/);
if (assetMatch && assetMatch[1]) { if (assetMatch && assetMatch[1]) {
if (!this._assetMap[assetMatch[1]]) { if (!this._assetMap[assetMatch[1]]) {
console.warn('Cannot find asset: ' + assetMatch[1]); debug('WARINING: Cannot find asset:', assetMatch[1]);
return null; return null;
} }
return this._assetMap[assetMatch[1]]; return this._assetMap[assetMatch[1]];