BeaconCMS / beacon_live_admin

Admin UI to manage content for sites built by Beacon
https://beaconcms.org
MIT License
36 stars 15 forks source link

Support `require` on tailwind config #151

Open leandrocp opened 1 month ago

leandrocp commented 1 month ago

The Visual Page Builder has built-in Tailwind integration with custom configuration per site, which means we have to dynamically load the tailwind config in order to apply the styles in the visual editor so every customization like fonts, colors, and others must match what the user see on the preview.

Since tailwind is a node package we're using https://github.com/mhsdesign/jit-browser-tailwindcss to mock some APIs to make it work on the browser, ie: whenever the user change something in the page builder it will compile the stylesheet again.

This is done at https://github.com/BeaconCMS/beacon_live_admin/blob/e466a84a5e376a3b849988b13a139e8ee93aa3f6/assets/svelte/components/PageWrapper.svelte#L26

The tailwind object is instantiated with a tailwind config: https://github.com/BeaconCMS/beacon_live_admin/blob/e466a84a5e376a3b849988b13a139e8ee93aa3f6/assets/svelte/components/PageWrapper.svelte#L21

The whole Page Builder is a Svelte application running inside a LiveView so that tailwindConfig is actually provided by the backend as a string.

That works fine for simple use cases but the problem is that we can't require modules (plugins) inside the config, ie: we can't call this in the config module:

let plugin = require('tailwindcss/plugin')

That breaks due to the async dynamic loading mechanism we use: https://github.com/BeaconCMS/beacon_live_admin/blob/e466a84a5e376a3b849988b13a139e8ee93aa3f6/assets/svelte/components/PageWrapper.svelte#L16-L19

Ref https://github.com/BeaconCMS/beacon_live_admin/issues/111#issuecomment-2083016691

leandrocp commented 1 month ago

Closed it by mistake

Serabe commented 1 week ago

Summary of today: