mirror of
https://github.com/status-im/metro.git
synced 2025-01-21 00:19:31 +00:00
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
0b9ca22fb2
commit
d613e622f4
21
react-packager/src/Bundler/index.js
vendored
21
react-packager/src/Bundler/index.js
vendored
@ -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…
x
Reference in New Issue
Block a user