Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support require on tailwind config #151

Closed
leandrocp opened this issue May 9, 2024 · 5 comments
Closed

Support require on tailwind config #151

leandrocp opened this issue May 9, 2024 · 5 comments
Assignees
Labels
area:visual-editor Impacts Page Visual Editor (Visual Page Builder) roadmap Priority issues that will be released in the short term
Milestone

Comments

@leandrocp
Copy link
Contributor

leandrocp commented May 9, 2024

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

const css = await tailwind.generateStylesFromContent($tailwindInput, [content])

The tailwind object is instantiated with a tailwind config:

const tailwind = window.createTailwindcss({ tailwindConfig })

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:

let b64moduleData = "data:text/javascript;base64," + btoa(twConfig.replace("module.exports = ", "export default "))
let configPromise = import(b64moduleData)
onMount(async () => {
const [_, { default: tailwindConfig }] = await Promise.all([tailwindJitPromise, configPromise])

Ref #111 (comment)

@leandrocp leandrocp added the area:visual-editor Impacts Page Visual Editor (Visual Page Builder) label May 9, 2024
@leandrocp leandrocp added this to Beacon May 9, 2024
@leandrocp leandrocp moved this to Todo in Beacon May 9, 2024
@leandrocp leandrocp added this to the v0.1.0 milestone May 9, 2024
@leandrocp leandrocp added the roadmap Priority issues that will be released in the short term label May 24, 2024
@leandrocp leandrocp self-assigned this May 24, 2024
@leandrocp
Copy link
Contributor Author

Closed it by mistake

@leandrocp leandrocp reopened this May 31, 2024
@Serabe
Copy link

Serabe commented Jun 21, 2024

Summary of today:

  • Tried to load @tailwindcss/forms and @tailwindcss/typography from the browser and it has the following issues:
    • Tailwind plugins uses CommonJS modules (the one with the module.export) and I cannot find a simple way to make it work from the browser (tried modifying the code and evaling it, but here it comes the second problem).
    • Tailwind plugins have dependencies, at the very least, on @tailwindcss/plugin.
  • The above makes that, even the JIT can use plugins, we cannot easily load them. All approaches to loading these modules go through pre-compilation.
  • I have a local instance of Beacon Admin and Beacon running. Next week I'll try to expose some basic plugins from Tailwind so they can be used from the browser. If successful, then we can discuss how far we want to get this, but it looks like a preferable way would be to do this on server when Tailwind v4 is released.

@Serabe
Copy link

Serabe commented Jul 5, 2024

BeaconCMS/beacon#542
#183

@leandrocp
Copy link
Contributor Author

Proof and example BeaconCMS/beacon_demo@d903e61

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:visual-editor Impacts Page Visual Editor (Visual Page Builder) roadmap Priority issues that will be released in the short term
Projects
Status: Todo
Development

No branches or pull requests

2 participants