A small demo that illustrates how you could use the asset provider in your own web application.
Make sure you have the dependencies installed for this demo:
npm install .
Once all dependencies are installed you can run the server using:
npm start
Once the server is started you can navigate your browser to:
There are 3 core files that drive this demo:
This is the actual file that implements the assets-provider
. This file
is converted to ES5 by the server.js
. The application it self is rather
simple:
- Imports
asset-provider
, and it's<Provider />
and<Asset />
components. - Specify a modification hook for the
pants
property, this will be used to change the color of homer's pants on the fly. - Creates a wrapping
<Provider />
that will load ourgodaddy.svg
bundle. This bundle will only contain a single asset which is the GoDaddy logo. - Render the asset by adding
<Asset name='godaddy' />
as child node of the<Provider />
- To make things interesting we've added another
<Provider>
as child which will load another bundle that contains thehomer
andtiger
svgs. - Add 3 more
<Asset name={godaddy|homer|tiger} />
as child elements of the extra<Provider />
. Whilegodaddy
is not available in this bundle, it will still render as the<Provider />
is aware of it's own context and will request the asset from the wrapping<Provider />
. - Set the property
pants=red
on of thehomer
assets to change the color of his pants from light blue to red. - Renders the Example component in the
example
container.
The server is in charge of serving the html
, js
and the svgs
asset bundle.
It comes with a dedicated API for generating bundles using the asset-bundle
library. The URL structure is a following:
http://localhost:8080/[lowercase names of the asset, separated by -].svgs
It uses the assets that are available in the asset
folder that is in the
root of this repository. So if you wish to generate a bundle containing just
the GoDaddy.svg logo you would request:
And if you wanted to include 3 svgs in your bundle you could request:
This gives you some insight on the bundles, and what they contain.
This is the default HTML page that gets loaded when you visit the URL. It's only
use is to load the index.js
so it starts the React application.