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.

After assembling the project in production mode, my styles disappear (version 1.3.1)

See original GitHub issue

My config:

require('dotenv').config();

module.exports = {
  head: {
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: '' },
    ],
    link: [
      {rel: 'stylesheet', href: 'https://fonts.googleapis.com/css?family=Montserrat:400,600,700&display=swap'}
    ],
  },

  css: [
    '~/assets/scss/common.scss',
    '~/assets/scss/3rd-party/font-awesome/font-awesome.scss',
  ],

  modules: [
    'nuxt-leaflet',
    '@nuxtjs/axios',
    '@nuxtjs/auth',
    '@nuxtjs/toast',
    ['@nuxtjs/router', {keepDefaultRouter: true, fileName: './routes'}],
  ],

  buildModules: [
    '@nuxtjs/tailwindcss'
  ],

  /*
    Modules.
   */
  auth: {
    strategies: {
      local: {
        endpoints: {
          login: { url: `${process.env.API_URL}/api/users/login`, method: 'post', propertyName: 'token' },
          logout: { url: `${process.env.API_URL}/api/users/logout`, method: 'post' },
          user: { url: `${process.env.API_URL}/api/users/me`, method: 'post', propertyName: false },
        },
      }
    }
  },

  toast: {
    duration: 3000,
  },

  build: {
    extractCSS: true,
  },
};

Styles from files do not get into the assembly for some reason (assets/scss/common.scss, assets/scss/3rd-party/font-awesome/font-awesome.scss)

In dev mode: image

In prod mode: (nuxt build && nuxt start) image

Sorry for my English 😢

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:17 (1 by maintainers)

github_iconTop GitHub Comments

9reactions
HoraceKeungcommented, Jan 24, 2020

Would also like to mention that, from my understanding, the way PurgeCSS works is very simple, it simply read through your source code and see if a CSS class is being used in your template. For example, you have a CSS class like this in style:

.my-button {
  padding: 1rem;
  background-color: blue;
}

But if you never use my-button in your template then PurgeCSS will remove it to keep the final bundle size small. And it will check for the exact string. Therefore the following will not work: Let say you have two classes:

.bg-red {
  background-color: red;
}
.bg-blue {
  background-color: blue;
}

Then in template

<div :class="`bg-${color}`">...</div>

Or

<div :class="`bg-${isRed ? 'red' : 'blue'}`">...</div>

As shown above, it is constructing the class with Template literals and depending on some state, the class will be different. And because PurgeCSS can’t find the exact strings “bg-red” and “bg-blue”, both classes will be removed.

Hence you need to do:

<div :class="${isRed ? 'bg-red' : 'bg-blue'}">...</div>

or

// Class Binding: https://vuejs.org/v2/guide/class-and-style.html#Object-Syntax
<div :class="{'bg-red': isRed, 'bg-blue': !isRed}">...</div>

This is also mentioned in TailwindCSS’ doc https://tailwindcss.com/docs/controlling-file-size/#writing-purgeable-html

7reactions
chuokecommented, Jan 20, 2020

@andruu

  1. Install it. I like yarn, so
yarn add tailwindcss 
  1. Add Tailwind to your CSS, you can follow the doc.
    I like to create a single file for the plugin, this named tailwind.css in the assets/css directory. put content as following
@import 'tailwindcss/base'; 
@import 'tailwindcss/components';
@import 'tailwindcss/utilities';
  1. Create your Tailwind config file
npx tailwind init
  1. Add config to nuxt.config.js
{
  css: ['@/assets/css/tailwind.css'],
  build: {
    postcss: {
      plugins: {
        tailwindcss: path.resolve(__dirname, './tailwind.config.js')
      }
    }
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

After assembling the project in production mode, my styles ...
My config: require('dotenv').config(); module.exports = { head: ... the project in production mode, my styles disappear (version 1.3.1) #55.
Read more >
A Case Study at Fläkt Woods in Jönköping - DiVA Portal
The aim of the thesis is to investigate the problem of missing items at the time of production. 1.3.1 Research Questions: 1. What...
Read more >
Gaea 1.3 now available - QuadSpinner Blog
We're happy to announce that Gaea 1.3 - our biggest and most powerful update yet - is ready for production! Download Gaea 1.3...
Read more >
TikZ and pgf
A copy of the license is included in the section entitled LATEX Project Public License. 2. Page 3. The TikZ and PGF Packages....
Read more >
Docker Compose release notes | Docker Documentation
Docker Compose now uses the native Docker CLI's build command when building images. Set the COMPOSE_DOCKER_CLI_BUILD=0 environment variable to disable this ...
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