Strip down asset data

Summary: This removes asset data that is not used at runtime from the bundle.

Reviewed By: javache

Differential Revision: D3628486

fbshipit-source-id: 33cd579c904e0b0e29502df39a4ff92cad43367c
This commit is contained in:
David Aurelio 2016-08-08 18:16:34 -07:00 committed by Facebook Github Bot 4
parent 0b9ca22fb2
commit d613e622f4

View File

@ -91,6 +91,12 @@ const validateOpts = declareOpts({
},
});
const assetPropertyBlacklist = new Set([
'files',
'fileSystemLocation',
'path',
]);
class Bundler {
constructor(options) {
@ -583,7 +589,10 @@ class Bundler {
bundle.addAsset(img);
const code = 'module.exports=' + JSON.stringify(img) + ';';
const code =
'module.exports=' +
JSON.stringify(filterObject(img, assetPropertyBlacklist))
+ ';';
return new ModuleTransport({
name: id,
@ -630,7 +639,7 @@ class Bundler {
type: assetData.type,
};
const json = JSON.stringify(asset);
const json = JSON.stringify(filterObject(asset, assetPropertyBlacklist));
const assetRegistryPath = 'react-native/Libraries/Image/AssetRegistry';
const code =
`module.exports = require(${JSON.stringify(assetRegistryPath)}).registerAsset(${json});`;
@ -726,4 +735,12 @@ function debouncedTick(progressBar) {
};
}
function filterObject(object, blacklist) {
const copied = Object.assign({}, object);
for (const key of blacklist) {
delete copied[key];
}
return copied;
}
module.exports = Bundler;