Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

246
Visualizações
dynamic classes with tailwindcss and eleventy

I am using eleventy.js with tailwindcss and postcss. In my setup, postcss does not seem to recognise dynamic classes like

md:pl-{{(loop.length-loop.index+1)*2}}

And so I never get them in the final css file. my package.json file has the following

"predev": "rimraf tmp && mkdir -p tmp/assets/css",
"dev": "npm run watch:css && npm run watch:app",
"watch:app": "cross-env NODE_ENV=development eleventy --input=src --output=tmp --serve",
"watch:css": "cross-env NODE_ENV=development postcss src/assets/css/tailwind.css > tmp/assets/css/style.css"

my postcss config looks like so

module.exports = {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  }
}

I am using postcss for tailwindcss along with eleventyjs, and so the loop comes from a nunjuncks for loop but the class doesn't show up in the css file generated by tailwind. Is there any way around this?

<a href="{{ title | url }}">
  {% set title = title.split('') %}
    <div class="text-lg md:text-xl uppercase flex flex-row justify-between md:justify-end">
      {% for letter in title %}
        <p class="md:pl-{{(loop.length-loop.index+1)*2}}">
          <span> {{ letter }} </span>
        </p>
      {% endfor %}
    </div>
  </a>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If you're using Tailwind v3.0 or later, or Tailwind 2 with the JIT compiler enabled, you can "safelist" the classes you're using.

// tailwind.config.js
module.exports = {
  // ...

  safelist: [
    {
      pattern: /pl-\d+/,
      variants: ['md'],
    },
  ],

  // ...
}

This will keep all pl utilities in your output CSS, regardless of whether they exist in the source. If you have more information on how long title can be and therefore which classes will be generated, then it's possible to be more specific in your regular expression.

// tailwind.config.js
module.exports = {
  // ...

  safelist: [
    {
      // for example only, adjust this depending on your output
      pattern: /pl-(-2|0|2|4|6|8)/,
      variants: ['md'],
    },
  ],

  // ...
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda