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:
parent
6ead260508
commit
24236a8926
|
@ -109,7 +109,7 @@ iOS saves multiple sizes for the same image in your Camera Roll, it is very impo
|
|||
For example, the result of `require('./my-icon.png')` might be:
|
||||
|
||||
```javascript
|
||||
{"__packager_asset":true,"path":"/Users/react/HelloWorld/my-icon.png","uri":"my-icon.png","width":591,"height":573}
|
||||
{"__packager_asset":true,"uri":"my-icon.png","width":591,"height":573}
|
||||
```
|
||||
|
||||
## Source as an object
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue