statamic / docs

Statamic Documentation
https://statamic.dev
Other
109 stars 373 forks source link

Document the process of building assets for addons #1421

Open duncanmcclean opened 1 month ago

duncanmcclean commented 1 month ago

This question has just come up on Discord:

Does anyone have any tips on how to distribute assets for an addon? I am developing an addon that needs some js and css on the frontend to work, I created frontend assets using vite but when used with the vite tag they only work for npm run build not dev

My response was:

You can either:

  1. Build them manually before you tag a release and include them in the Git repository. Then, in your service provider, you can publish the files to the site's public/vendor directory.
  2. A little more advanced way (which we do at Statamic, and I use for my addons), is to ignore committing assets to the repository, then building them as part of a GitHub Actions workflow used for releasing. Jason's built a package which'll then copy over the assets from the GitHub release into the site's vendor directory upon composer update.

It feels like we could do with some more detailed documentation around how addon developers should handle this.

afonic commented 1 month ago

Hey Duncan thanks for this and for your help. Just to add my notes and possibly I could help with writing a draft if I get all my facts straight.

Building assets for the frontend and the backend is a bit more complex and just one or the other. If we assume that the dependencies can be the same, we can probably document how to have separate vite config files?

Also I am not 100% sure what is the recommended way to distribute them. For the Statamic form helper you've used a "normal" import, however that leaves cache busting to the dev. In some addons the frontend assets might change often. Maybe we need to document also how to include them using the Vite tag or something similar?