This package has been deprecated

Author message:

Package has been moved to https://www.npmjs.com/package/@nimpl/classnames-minifier

next-classnames-minifier
TypeScript icon, indicating that this package has built-in type declarations

2.3.5 • Public • Published

Next classnames minifier

npm version

Library for configuring style (css/scss/sass) modules to generate compressed classes (.header -> .a, .nav -> .b, ..., .footer -> .aad, etc.) with support for changes and rebuilding without clearing the built application.

Important

This description is for >=2.2.0. See instructions for previous versions at next-classnames-minifier/tree/2.1.1

Reasons

Compressing classes can reduce the size of the generated html and css by up to 20%, which will have a positive effect on page rendering and metrics (primarily FCP)

Installation

Using npm:

npm i next-classnames-minifier

Using yarn:

yarn add next-classnames-minifier

Usage

Create next.config.js file in your project and apply the library.

Base:

const withClassnamesMinifier = require('next-classnames-minifier').default;

module.exports = withClassnamesMinifier({ type: process.env.NODE_ENV === 'development' ? 'none' : 'minified' })({
    // next.js config
});

With next-compose-plugins:

const withClassnamesMinifier = require('next-classnames-minifier').default;
const withPlugins = require('next-compose-plugins');

module.exports = withPlugins([
    [withClassnamesMinifier({ type: process.env.NODE_ENV === 'development' ? 'none' : 'minified' })]
], nextConfig);

Configuration

Options

  • type - variant of changing classnames method;
  • templateString - custom template string, only works with "custom" type;
  • prefix - custom prefix that will be added to each updated class;
  • reservedNames - array of reserved names that should not be used by this package (must include prefix);

Type

next-classname-minifier has 3 types of changing classnames:

  • minified — the main option. It is not recommended to use this option in development mode, it may slow down the update;
  • custom — create a class using a template string rule, can be used for debugging;
  • none — use the default CSS modules option, default for development mode;

It is recommended to disable minification for development.

Configuration example:

module.exports = withPlugins([
    [withClassnamesMinifier({ type: process.env.NODE_ENV === 'development' ? 'none' : 'minified' })]
], nextConfig);

Custom mode example:

module.exports = withPlugins([
    [withClassnamesMinifier({ type: 'custom', templateString: '[path][name]__[local]_[hash:base64:5]' })]
], nextConfig);

License

MIT

Package Sidebar

Install

npm i next-classnames-minifier

Weekly Downloads

133

Version

2.3.5

License

MIT

Unpacked Size

29.2 kB

Total Files

29

Last publish

Collaborators

  • vordgi