Search code examples
clojurescriptshadow-cljs

How to manage static files in shadow-cljs?


For example, I have an index.html for the project.

I'd like that whenever I build the project, it's automatically copied to the public project. Is there a built-in way to achieve this?


Solution

  • There is a built-in hook to copy (and potentially modify) a HTML file.

    In can be configured in your build config via

    :build-hooks
    [(shadow.html/copy-file "src/html/index.html" "public/index.html")]
    

    All paths are relative to the project root. This only copies that specified file, nothing else. You could write your own hook to copy more or just use a separate command to copy the files manually.

    I typically just put all the files in their "final" place from the start and just have a public/js folder or so that is git-ignored that I can delete and will be recreated when I build my CLJS. That way there is no need to copy anything to begin with. ;)