reflex icon indicating copy to clipboard operation
reflex copied to clipboard

External assets

Open abulvenz opened this issue 1 year ago β€’ 3 comments

When referencing external modules, the files for the asset folder should be somehow shippable. This is a proposal for a simple helper function that copies the files to the assets folder of the app that is currently compiled.

# library_module.index.py

# In the library module reference the 
# asset files with the relative file path to the including script.
@rx.page("/")
def index() -> rx.Component:
    return rx.center(
        rx.image(src=rx.asset("test.png",dir="subfolder"))
    )

During compilation those files are copied to assets/external/library_module/index/subfolder/test.png.

In case you want to make assets from your library includable for calling modules, you can expose them like this:

class Assets:
    test_png = rx.asset("test.png", "hang_it_up")
    script_js = rx.asset("my_component_logic.js")

abulvenz avatar May 03 '24 15:05 abulvenz

@abulvenz how about symlinking instead of copying?
Edit: Not sure how symlinks behave on Windows

benedikt-bartscher avatar May 04 '24 11:05 benedikt-bartscher

@abulvenz how about symlinking instead of copying? Edit: Not sure how symlinks behave on Windows

Symlink doesn't work on Windows, we had this in the beginning for syncing between assets and .web/public folder, but had to remove it for Windows.

Lendemor avatar May 05 '24 18:05 Lendemor

Symlink doesn't work on Windows, we had this in the beginning for syncing between assets and .web/public folder, but had to remove it for Windows.

@Lendemor Should I change it back? :mechanic:

Is anything else missing here?

abulvenz avatar May 07 '24 09:05 abulvenz

@Lendemor Is it possible that I cancelled your approval by merging main? Sorry. :bowl_with_spoon:

abulvenz avatar May 27 '24 20:05 abulvenz