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

Browser version doesn't work (non-ES module version) #509

Open
guiprav2 opened this issue May 21, 2024 · 7 comments
Open

Browser version doesn't work (non-ES module version) #509

guiprav2 opened this issue May 21, 2024 · 7 comments
Labels
📚 Documentation The documentation is lacking or missing something

Comments

@guiprav2
Copy link

guiprav2 commented May 21, 2024

Documentation Is:

Not Sure?

Link to relevant page or pages

Please Explain in Detail...

If I create a blank page with the following HTML, I don't see an underline under the h1:

<!doctype html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/@twind/core@1" crossorigin></script>
<script>twind.install({})</script>
</head>
<body>
<h1 class="underline">Hello!</h1>
</body>
</html>

Additionally, if I try the version with presets I get a console error:

<!doctype html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/combine/npm/@twind/core@1,npm/@twind/preset-autoprefix@1,npm/@twind/preset-tailwind@1" crossorigin></script>
<script>
  twind.install({
    presets: [twind.presetAutoprefix(/* options */), twind.presetTailwind(/* options */)],
  });
</script>
</head>
<body>
<h1 class="underline">Hello!</h1>
</body>
</html>

The error message says:

Uncaught TypeError: e is undefined
    presetTailwind https://cdn.jsdelivr.net/combine/npm/@twind/core@1,npm/@twind/preset-autoprefix@1,npm/@twind/preset-tailwind@1:34
    <anonymous> https://cdn.jsdelivr.net/combine/npm/@twind/core@1,npm/@twind/preset-autoprefix@1,npm/@twind/preset-tailwind@1:34
[preset-tailwind@1:34:10723](https://cdn.jsdelivr.net/combine/npm/@twind/core@1,npm/@twind/preset-autoprefix@1,npm/@twind/preset-tailwind@1)
Uncaught TypeError: twind.presetTailwind is not a function
    <anonymous> file:///home/gui/prog/webfoundry3/test.html:5

Your Proposal for Changes

I don't know, it should work, right?

Alternatives considered

No response

@guiprav2 guiprav2 added the 📚 Documentation The documentation is lacking or missing something label May 21, 2024
@craigerskine
Copy link

This is how I do it... no errors:

<!doctype html>
<html lang="en" class="bg-transparent antialiased">

  <head>
    <meta charset="utf-8" />
    <meta http-equiv="x-ua-compatible" content="ie=edge" />
    <title>Foo</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, interactive-widget=overlays-content" />
  </head>

  <body class="bg-gray-50 text-gray-700 !block" style="display: none;">
    <div id="app" class="min-h-screen flex-(& col) divide-(y gray-500/25)" x-cloak>
      <header class="py-8 px-4 w-full flex-none">
        <div class="mx-auto w-full max-w-7xl">...</div>
      </header>
      <main class="px-4 py-8 w-full flex-1">
        <section class="mx-auto w-full max-w-7xl">
          <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed massa metus, tempus sit amet rhoncus nec, suscipit et ligula. Donec in sem libero, quis dapibus nisi. Nunc bibendum ultrices tellus sed molestie. Donec venenatis, quam non fringilla congue, nisl nisl eleifend nibh, et pellentesque lorem turpis et erat. Nulla ac nisi odio, in rhoncus urna. Duis congue urna lorem, et auctor tellus. Phasellus eleifend varius rhoncus. In hac habitasse platea dictumst. Quisque nec tincidunt neque. Proin vitae tortor justo. Ut sem turpis, viverra eget tristique sed, accumsan in justo.</p>
        </section>
      </main>
      <footer class="py-8 px-4 w-full flex-none">
        <div class="mx-auto w-full max-w-7xl">...</div>
      </footer>
    </div>
    <script type="module">
      // twind
      import { install, injectGlobal } from 'https://esm.run/@twind/core';
      import presetAutoprefix from 'https://esm.run/@twind/preset-autoprefix';
      import presetTailwind from 'https://esm.run/@twind/preset-tailwind';
      install({
        presets: [presetAutoprefix(), presetTailwind()],
        darkMode: 'class',
        hash: false,
        theme: {
          extend: {
            //...
          },
        },
        rules: [
          // ...
        ],
      });
      // global css
      injectGlobal`
        @layer base {
          [x-cloak] { @apply hidden; }
        }
      `
    </script>
  </body>

</html>

@guiprav2
Copy link
Author

Try without import. For this project I can't use ES modules and that's probably where the problem is coming from.

@guiprav2 guiprav2 changed the title Browser version doesn't work Browser version doesn't work (non-ES modules version) May 29, 2024
@guiprav2 guiprav2 changed the title Browser version doesn't work (non-ES modules version) Browser version doesn't work (non-ES module version) May 29, 2024
@craigerskine
Copy link

craigerskine commented May 29, 2024

Try this:

<!doctype html>
<html>
  <head>
  </head>
  <body>
    <h1 class="underline">Hello!!!</h1>

    <script src="https://cdn.twind.style/" crossorigin></script>
    <script>
      twind.install({
        presets: [
          twind.presetTailwind(),
          twind.presetAutoprefix(),
        ],
      });
    </script>
  </body>
</html>

@guiprav2
Copy link
Author

That works. I'm using the CDN version now, but the Tailwind documentation seems to indicate it's not recommended in production? From https://tailwindcss.com/docs/installation/play-cdn:

The Play CDN is designed for development purposes only, and is not the best choice for production.

I'm not sure that applies to Twind. What's the difference between those versions anyway? Do you know? Thanks!

@craigerskine
Copy link

craigerskine commented May 30, 2024

If you are not using Twind for its rules and amazing grouping syntax. Then vanilla Tailwind would be ideal.

Personally I cannot live without stuff like:

// grouping
grid-(& cols-1) md:(grid-cols-4)
after:(w-4 h-4 bg-current opacity-25 rounded-full)
[&:has(:invalid)_[class*='field-error']]:(block visible opacity-100)

// fragments
:class="'bg-'+ item.color +'-400'"

If you want to avoid a build system (I totally understand), you could just visit this url:
https://cdn.twind.style/

Just grab the code and paste into a js file or a script block in your html and you get all the benefits of Twind without any CDN or build system. You can even include any presets you like in the initial url.

Tailwind's play is pretty massive 470K. Twind's is like 13K or something.

With Tailwind you get all the latest stuff. Twind hasn't been updated in like 2 year or something. Personally, I don't need a lot of the newer Tailwind stuff.

Even if Twind goes under, I'll probably end up switching to Master CSS or UnoCSS over Tailwind and its dumb build requirement.

@guiprav2
Copy link
Author

Damn, I hope Twind regains traction. I'm building a site builder entirely around Tailwind classes (https://webfoundry.app), but since it all runs in the browser Tailwind's build system is a non-starter. Hopefully it's not too hard to add new stuff to Twind using config rules and stuff...

@craigerskine
Copy link

craigerskine commented May 31, 2024

Even if development ends (which it looks like it already has), you will still be able to extend it and do stuff like:

<p class="print:([text-wrap:pretty])">...

to add new CSS rules even before they are added to vanilla Tailwind.

The only reason to update the current Twind is to add parity syntax support with Tailwind. It's not truly necessary IMO. I plan on using it until browsers stop supporting the Js.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📚 Documentation The documentation is lacking or missing something
Projects
None yet
Development

No branches or pull requests

2 participants