npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@filiphsandstrom/next-purge-css-modules

v0.0.0-unstable.1

Published

Easily remove unused css-module code in your Next.js application

Downloads

3

Readme

Contents

Installation

next-purge-css-modules can be installed using your favourite JavaScript package manager.

yarn add next-purge-css-modules --dev
npm install next-purge-css-modules --save-dev

Example Usage

If your Next.js project does not already contain one, create a next.config.js file in the root of your project directory.

const withPurgeCSSModules = require('next-purge-css-modules');

/** @type {import('next-purge-css-modules').PurgeConfig} */
const purgeConfig = { ... };

module.exports = withPurgeCSSModules(purgeConfig);

You can read more about the advanced configuration of Next.js on the official documentation site.

Configuration

This plugin comes preconfigured with some sensible defaults options. However, you are free to alter this configuration to suit your project needs with the use of the custom purge config object via the next.config.js file.

Additionally, you can also pass your custom next config object as the function's second argument.

interface PurgeCSSModulesOptions {
  content?: string | string[];
  enableDevPurge?: boolean;
  fontFace?: boolean;
  keyframes?: boolean;
  safelist?: UserDefinedSafelist;
  variables?: boolean;
}
const path = require('path');
const withPurgeCSSModules = require('next-purge-css-modules');

/** @type {import('next').NextConfig} */
const nextConfig = {
  ...
};

/** @type {import('next-purge-css-modules').PurgeConfig} */
const purgeConfig = {
  content: path.join(__dirname, 'src/**/*.{js,jsx,ts,tsx}'),
  enableDevPurge: true,
  safelist: ['body', 'html'],
};

module.exports = withPurgeCSSModules(purgeConfig, nextConfig);

content

This option tells next-purge-css-modules which files to look through to check for unused css-modules. You can either supply these files as absolute paths or as file path globs and they can either be a single path or an array.

The default value looks at all JavaScript/TypeScript files in the default Next.js pages directories (app/**/*.{js,jsx,ts,tsx}, pages/**/*.{js,jsx,ts,tsx}, src/app/**/*.{js,jsx,ts,tsx} and src/pages/**/*.{js,jsx,ts,tsx}).

enableDevPurge

By default, your css-module code will only be purged when a production build is generated. You can set this flag to true to enable css-modules purging when running your Next.js project in development mode.

fontFace

If there are any unused @font-face rules, setting this flag to true will purge them from the final output. By default is false.

keyframes

Any unused animation keyframes found within your css-module code will be purged from the final output when this flag is set to true. By default is false.

safelist

By supplying an array of CSS selectors to the safelist option, you can tell next-purge-css-modules which selectors you wish to ensure are not purged. By default is ['body', 'html']

To read more about the safelist configuration option, you can refer to the official PurgeCSS documentation.

variables

When you are using Custom Properties (CSS variables), or a library using them such as Bootstrap, setting this flag to true will purge them from the final output.

Usage With Sass

next-purge-css-modules works directly out of the box with Next.js projects set up to use Sass.

You can refer to the official Next.js Sass documentation to ensure your project is set up correctly.

Contributing

Thanks for taking the time to contribute! Before you get started, please take a moment to read through our contributing guide. The focus area for next-purge-css-modules right now is fixing potential bugs.

However, all issues and PRs are welcome!

License

MIT - see the LICENSE.md file for details