[react-packager] Add assetRoots option

This commit is contained in:
Amjad Masad 2015-03-18 19:13:30 -07:00
parent 13e054a714
commit 319ea3242a
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' +
' ===============================================================\n' +
' | Running packager on port ' + options.port + '. \n' +
@ -97,6 +101,7 @@ function getAppMiddleware(options) {
blacklistRE: blacklist(false),
cacheVersion: '2',
transformModulePath: require.resolve('./transformer.js'),
assetRoots: options.assetRoots,
});
}

View File

@ -134,13 +134,12 @@ DependecyGraph.prototype.resolveDependency = function(
fromModule,
depModuleId
) {
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]);
debug('WARINING: Cannot find asset:', assetMatch[1]);
return null;
}
return this._assetMap[assetMatch[1]];