-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
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
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Hello Bundled World</title> | ||
<meta http-equiv="content-type" content="text/html; charset=utf-8"> | ||
<meta name="viewport" content="width=320, user-scalable=no"> | ||
<style type="text/css"> | ||
body { | ||
margin: 0; | ||
padding: 0; | ||
font: 62.5% arial, sans-serif; | ||
background: #ccc; | ||
} | ||
h1 { | ||
padding: 45px; | ||
margin: 0; | ||
text-align: center; | ||
color: #f33; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<h1>Hello Bundled World</h1> | ||
</body> | ||
</html> |
3 comments
on commit 81fb985
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gre There's currently no way to add a catch-all AFAICT. Feel free to add a PR with any additional extensions you want. Unfortunately they have to be added in three places at the moment (two js files, and the flow regex), but hopefully we can find a DRYer way to extend the list at some point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gre note that require() for assets just returns the uri inside an object, it doesn't return the actual data - you'd still have to load that yourself if you aren't displaying the asset in a <WebView/>
or <Image/>
tag. You'll also need to unwrap the result using resolveAssetSource() if you want to pass the raw uri to an XMLHttpRequest, etc.
For text or shader code, you might be better off embedding them as a string literal in a .js file, and requiring that, so you get the raw data directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok make sense, thanks for your answer. I guess for now it's fine to just use .js as you said. I wish eventually we could have a way to have an extensible system (like for webpack loaders) so we can have third party plugins for specific logic for a given use-case (for instance using glslify
https://github.com/stackgl/glslify-loader for shader code)
Does this mean any extension not in this list will be unsupported? Is there a default catchall mecanism? For instance I would love to have support for
.frag
(fragment shader) or any.txt
file (just as row text).