Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
chore: improve mangling class names on production
Browse files Browse the repository at this point in the history
  • Loading branch information
nekofar committed Apr 8, 2023
1 parent 35b7176 commit a3d9233
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,34 @@ const nextConfig = {
images: {
unoptimized: true,
},
webpack: (config, {dev, isServer}) => {
webpack: (config, { dev, isServer }) => {

if (!dev) {
const MangleCssClassPlugin = require('mangle-css-class-webpack-plugin');
config.plugins.push(new MangleCssClassPlugin({
classNameRegExp: '((hover|focus|xs|md|sm|lg|xl)[\\\\]*:)*-?tw-[a-z_-][a-zA-Z0-9_-]*',
ignorePrefixRegExp: '((hover|focus|xs|md|sm|lg|xl)[\\\\]*:)*',
log: true,
classGenerator: (original, opts, context) => {
if (classNames[original]) {
return classNames[original];
}

let nextId;

do {
// Class name cannot start with a number.
nextId = generateClassName();
} while (/^[0-9_-]/.test(nextId));

return (classNames[original] = nextId);
}
}));
const MangleCssClassPlugin = require('mangle-css-class-webpack-plugin')
config.plugins.push(
new MangleCssClassPlugin({
classNameRegExp:
'(([a-zA-Z-:]*)[\\\\\\\\]*:)*([\\\\\\\\]*!)?-?tw-[a-zA-Z-]([a-zA-Z0-9-]*([\\\\\\\\]*(\\%|\\#|\\.|\\[|\\]|\\/))*)*',
log: process.env.NODE_ENV === 'development',
classGenerator: (original, opts, context) => {
if (classNames[original]) {
return classNames[original]
}

let nextId

do {
// Class name cannot start with a number.
nextId = generateClassName()
} while (/^[0-9_-]/.test(nextId))

return (classNames[original] = nextId)
},
}),
)
}

return config;
return config
},
}

Expand Down

0 comments on commit a3d9233

Please sign in to comment.