Gatsby

提示

此外掛程式是由 @anantoghosh在新視窗中開啟 所建立,而此頁面是自 ReadMe 擷取的。您可以在 外掛程式儲存庫在新視窗中開啟 找到更多資訊

您可以使用 PurgeCSS 從 Gatsby 專案中的 css/sass/less/stylus 檔案和模組中移除未使用的 css。支援 tailwind、bootstrap、bulma 等。

警告

這不是安裝後就可以不管的外掛程式。預設情況下,它也可能會移除必要的樣式。

📘 在此處閱讀最新文件。在新視窗中開啟變更日誌在新視窗中開啟

示範

gatsby-starter-bootstrap在新視窗中開啟 中使用時

demo

gatsby-starter-bootstrap-cv在新視窗中開啟 中使用(預設安裝)

demo

支援的檔案

安裝

npm i gatsby-plugin-purgecss

用法

在其他 css/postcss 外掛程式之後加入外掛程式

// gatsy-config.js
module.exports = {
  plugins: [
    `gatsby-plugin-stylus`,
    `gatsby-plugin-sass`,
    `gatsby-plugin-less`,
    `gatsby-plugin-postcss`,
    // Add after these plugins if used
    { 
      resolve: `gatsby-plugin-purgecss`,
      options: {
        printRejected: true, // Print removed selectors and processed file names
        // develop: true, // Enable while using `gatsby develop`
        // tailwind: true, // Enable tailwindcss support
        // whitelist: ['whitelist'], // Don't remove this selector
        // ignore: ['/ignored.css', 'prismjs/', 'docsearch.js/'], // Ignore files/folders
        // purgeOnly : ['components/', '/main.css', 'bootstrap/'], // Purge only these files/folders
      }
    }
  ]
};

TLDR