Assets
If a wrapped component depends on assets such as images, scripts, or
stylesheets, these can be kept adjacent to the component code and
included in the final build using the rx.asset
function.
rx.asset
returns a relative path that references the asset in the compiled
output. The target files are copied into a subdirectory of assets/external
based on the module where they are initially used. This allows third-party
components to have external assets with the same name without conflicting
with each other.
For example, if there is an SVG file named wave.svg
in the same directory as
this component, it can be rendered using rx.image
and rx.asset
.
Local Components
You can also wrap components that you have written yourself. For local components (when the code source is directly in the project), we recommend putting it beside the files that is wrapping it.
You can then use the path obtained via rx.asset
to reference the component path.
So if you create a file called hello.js
in the same directory as the component with this content:
You can specify the library as follow (note: we use the public
directory here instead of assets
as this is the directory that is served by the web server):
Local Packages
If the component is part of a local package, available on Github, or
downloadable via a web URL, it can also be wrapped in Reflex. Specify the path
or URL after an @
following the package name.
Any local paths are relative to the .web
folder, so you can use ../
prefix
to reference the Reflex project root.
Some examples of valid specifiers for a package called
@masenf/hello-react
are:
- GitHub:
@masenf/hello-react@github:masenf/hello-react
- URL:
@masenf/hello-react@https://github.com/masenf/hello-react/archive/refs/heads/main.tar.gz
- Local Archive:
@masenf/hello-react@../hello-react.tgz
- Local Directory:
@masenf/hello-react@../hello-react
It is important that the package name matches the name in package.json
so
Reflex can generate the correct import statement in the generated javascript
code.
These package specifiers can be used for library
or lib_dependencies
.
Counter
Although more complicated, this approach is useful when the local components have additional dependencies or build steps required to prepare the component for use.
Some important notes regarding this approach:
- The repo or archive must contain a
package.json
file. prepare
orbuild
scripts will NOT be executed. The distribution archive, directory, or repo must already contain the built javascript files (this is common).