question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use TailwindCSS wtih @nxext/svelte?

See original GitHub issue

Hey, how can I use TailwindCSS properly with Svelte? I’ve tried to use custom rollup.config.js, but it does not work.

Always received the following error:

Error during bundle: Unexpected character '@' (Note that you need plugins to import files that are not JavaScript)

I think something is with postcss, but not sure.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
andrasbacsaicommented, Oct 12, 2020

Wow, cool. It just works. And as we are adding tailwind into .svelte, we can use @apply. 🎉 Also, with this configuration, we could use purge in development to improve postcss performance (tailwind.config.js):

module.exports = {
    future: {
        removeDeprecatedGapUtilities: true,
        purgeLayersByDefault: true
    },
    purge: {
      enabled: true,
      content: ["./apps/**/*.svelte", "./apps/**/*.html"],
      whitelistPatterns: [/svelte-/],
    },
    theme: {
      extend: {},
    },
    variants: {},
    plugins: [],
  } 
1reaction
DominikPiepercommented, Oct 12, 2020

@andrasbacsai I added another maybe helpful option to archive that, you’re able to hook in a method to configure the svelte preprocessor with something like this:

function setSveltePreprocessOptions(options) {
  return {
    postcss: {
      plugins: [
        require('postcss-import')(),
        require('postcss-nested')(), // Remove if you can't wan't to use nested structures.
        require('tailwindcss')(options.projectRoot + '/tailwind.config.js'),
      ]
    }
  };
}

module.exports = setSveltePreprocessOptions;

now you’re able to e.g. add a Tailwind.svelte with

<style global>
	@tailwind base;
    @tailwind components;
    @tailwind utilities;
</style>

and import it in your app component

Read more comments on GitHub >

github_iconTop Results From Across the Web

Install Tailwind CSS with Nuxt.js
Using npm, install tailwindcss and its peer dependencies, as well as @nuxt/postcss8 , and then run the init command to generate the tailwind.config.js...
Read more >
Pairing Nuxt 3 with TailwindCSS and Supabase
Learn how to work with TailwindCSS and Supabase in Nuxt 3 projects.
Read more >
How to Build a To-do app with Svelte, Strapi & Tailwind CSS
In the tutorial, we will build REST API using Strapi and consume our data from the client-side using Axios and make our components...
Read more >
How to use Tailwind CSS with Svelte
Create beautiful, custom components with Tailwind CSS to style your Svelte app using this step-by-step tutorial.
Read more >
How to Install Tailwind CSS 3 in Nuxt 3 - Frontendshape
Create Nuxt 3 Project. Run below command to create nuxt 3 project. ... After run it look like this, so follow the setps....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found