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.

Some styles are not applied in production mode with "srcDir" nuxt.config.js option.

See original GitHub issue

Version

@nuxtjs/tailwindcss: 2.0.0 nuxt: 2.12.0

What is actually happening?

Hi, this is Peter.

I tried to install this module, worked perfectly in dev mode, but some tailwind css has not been applied when I executed nuxt build and nuxt start.

Without “srcDir” option in production mode

image image

As you can see, tailwind’s class styles .bg-black and .container are applied.

With “srcDir” options in production mode

image image

The problem is that .container style is applied, .bg-black is not applied with all scripts are in srcDir.

I tried to install all dependencies by using both npm and yarn, but got same result.

Please let me know If my configuration is wrong! Thank you.


[10, August] @nuxtjs/tailwindcss has been updated from 2.x to 3.0, still got same issue.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:10

github_iconTop GitHub Comments

6reactions
Atinuxcommented, Sep 25, 2020

Hi @misikoff

First, you need to move tailwind.config.js in the src/ directory OR to define configPath: '~~/tailwind.config.js' (~~ is the alias for rootDir, see https://nuxtjs.org/guides/directory-structure/assets#aliases).

Then you will see a message saying:

Merging Tailwind config from ~/tailwind.config.js

I actually merged #170 and released the v3.1.0 supporting the srcDir as well as TypeScript, so you can update your dependency and it’s good to go 🚀

5reactions
nielsdB97commented, May 28, 2020

@peterkimzz I am currently running into the same problem.

I found that the problem is caused by PurgeCSS, which is a tool that strips all unused CSS from your application build. This way whatever Tailwind utitilies you don’t use are also not shipped to the user, resulting in smaller payloads and thereby better performance. PurgeCSS is only enabled in production mode, which is why your development environment works just fine but the output of both the build and generate scripts don’t.

In my project I write my pages and components in .vue files. For the <style> blocks with @apply directives everything seems to work just fine. However the classes used directly in the <template> tag are somehow not found and therefore purged. We need to check both the <template> block as well as the <style> block to preserve the classes used.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Some styles are not applied in production mode with "srcDir ...
Hi, this is Peter. I tried to install this module, worked perfectly in dev mode, but some tailwind css has not been applied...
Read more >
nuxt styles won't be applied in production mode - Stack Overflow
i solved my issue by adding this paragraph to nuxt.config.js build configuration. that's actually what i figured out about it. i've had ...
Read more >
Nuxt configuration file
This option lets you define the development or production mode of Nuxt (important when you use Nuxt programmatically). nuxt.config.js
Read more >
The build Property - Nuxt
Customize Babel configuration for JavaScript and Vue files. .babelrc is ignored by default. Type: Object; See babel-loader options and babel options; Default: { ......
Read more >
The srcDir Property - Nuxt
The srcDir property. Define the source directory of your Nuxt application. Type: String; Default: rootDir value. If a relative path is specified it...
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