mirror of https://github.com/status-im/metro.git
Support non-image assets in packager
Summary: public The packager currently assumes that all assets that are not JSON or JS files must be images. Although it is possible to add other extension types, they crash the packager if you try to require them, because it attempts to get their dimensions, assuming that they are an image. This is a crude workaround for that problem, which skips the image-specific processing for non-image assets, but really it would be better if the packager was properly aware of different asset types and treated them differently (e.g. for sounds it could include the duration, for HTML pages it could parse and include linked CSS files, etc). I've also added an example of using `require('...')` to load a packager-managed HTML page in the UIExplorer WebView example. In future I anticipate that all static asset types (sounds, fonts, etc.) could be handled in this way, which allows them to be edited or added/removed on the fly instead of needing to restart the app. Reviewed By: martinbigio Differential Revision: D2895619 fb-gh-sync-id: cd93794ca66bad838621cd7df3ff3c62b5645e85
This commit is contained in:
parent
38cea2edeb
commit
e90d06dbed
|
@ -554,8 +554,14 @@ class Bundler {
|
||||||
assetUrlPath = assetUrlPath.replace(/\\/g, '/');
|
assetUrlPath = assetUrlPath.replace(/\\/g, '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test extension against all types supported by image-size module.
|
||||||
|
// If it's not one of these, we won't treat it as an image.
|
||||||
|
let isImage = [
|
||||||
|
'png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp', 'psd', 'svg', 'tiff'
|
||||||
|
].indexOf(path.extname(module.path).slice(1)) !== -1;
|
||||||
|
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
sizeOf(module.path),
|
isImage ? sizeOf(module.path) : null,
|
||||||
this._assetServer.getAssetData(relPath, platform),
|
this._assetServer.getAssetData(relPath, platform),
|
||||||
]).then(function(res) {
|
]).then(function(res) {
|
||||||
const dimensions = res[0];
|
const dimensions = res[0];
|
||||||
|
@ -564,8 +570,8 @@ class Bundler {
|
||||||
__packager_asset: true,
|
__packager_asset: true,
|
||||||
fileSystemLocation: path.dirname(module.path),
|
fileSystemLocation: path.dirname(module.path),
|
||||||
httpServerLocation: assetUrlPath,
|
httpServerLocation: assetUrlPath,
|
||||||
width: dimensions.width / module.resolution,
|
width: dimensions ? dimensions.width / module.resolution : undefined,
|
||||||
height: dimensions.height / module.resolution,
|
height: dimensions ? dimensions.height / module.resolution : undefined,
|
||||||
scales: assetData.scales,
|
scales: assetData.scales,
|
||||||
files: assetData.files,
|
files: assetData.files,
|
||||||
hash: assetData.hash,
|
hash: assetData.hash,
|
||||||
|
|
|
@ -58,7 +58,12 @@ const validateOpts = declareOpts({
|
||||||
},
|
},
|
||||||
assetExts: {
|
assetExts: {
|
||||||
type: 'array',
|
type: 'array',
|
||||||
default: ['png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp'],
|
default: [
|
||||||
|
'bmp', 'gif', 'jpg', 'jpeg', 'png', 'psd', 'svg', 'webp', // Image formats
|
||||||
|
'm4v', 'mov', 'mp4', 'mpeg', 'mpg', 'webm', // Video formats
|
||||||
|
'aac', 'aiff', 'caf', 'm4a', 'mp3', 'wav', // Audio formats
|
||||||
|
'html', // Document formats
|
||||||
|
],
|
||||||
},
|
},
|
||||||
transformTimeoutInterval: {
|
transformTimeoutInterval: {
|
||||||
type: 'number',
|
type: 'number',
|
||||||
|
|
Loading…
Reference in New Issue