3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

postcss で purgecss すると tailwindcss の breakpoint が消えてしまう

Posted at
tailwind.css
  .lg\:bg-red-700 {
    --bg-opacity: 1;
    background-color: #c53030;
    background-color: rgba(197, 48, 48, var(--bg-opacity));
  }

というCSSがあり、

index.html
<div class="lg:bg-red-700">Hello</div>

という HTML があります。

purgecss の設定ファイルは以下のようになっており、

postcss.config.js
const purgecss = require("@fullhuman/postcss-purgecss")

module.exports = {
  plugins: [
    purgecss({
      content: ["./**/*.html"],
    }),
  ],
}

これで postcss を実行すると tailwind.css の .lg\:bg-red-700 が消えてしまいます。

おそらく : をエスケープしている \ が入っているためヒットしないのだと思います。

なので、公式サイトを頼りに postcss.config.js の設定を書き換えます。
defaultExtractor の行を追加します。

postcss.config.js
const purgecss = require("@fullhuman/postcss-purgecss")

module.exports = {
  plugins: [
    purgecss({
      content: ["./**/*.html"],
      defaultExtractor: (content) => content.match(/[\w-/:]+(?<!:)/g) || [],
    }),
  ],
}

これでうまくいきました。

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?