Skip to content

Commit

Permalink
Merge pull request #14 from vordgi/ncm-13
Browse files Browse the repository at this point in the history
ncm-13 add custom mode instead of detailed
  • Loading branch information
vordgi authored Sep 10, 2023
2 parents fd85e7c + 555d91c commit d0a63b1
Show file tree
Hide file tree
Showing 13 changed files with 317 additions and 73 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ module.exports = withPlugins([
## Configuration
next-classname-minifier has 3 types of changing classnames:

* minified - the main option. It is highly not recommended to use this option for development mode (_it is too unstable in dev mode_);
* detailed - can be used for debugging, default for development mode;
* none — use the default CSS modules option;
* minified the main option. It is highly not recommended to use this option for development mode (_it is too unstable in dev mode_);
* custom — create a class using a [template string](https://webpack.js.org/configuration/output/#template-strings) rule, can be used for debugging;
* none — use the default CSS modules option, default for development mode;

You can choose different options for development and production.

Expand All @@ -56,6 +56,13 @@ module.exports = withPlugins([
], nextConfig);
```

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

## License

[MIT](https://github.com/vordgi/next-classnames-minifier/blob/main/LICENSE)
1 change: 1 addition & 0 deletions deps.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'css-loader/dist/utils';
230 changes: 228 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next-classnames-minifier",
"version": "1.0.0",
"version": "1.1.0",
"description": "Library for configuring style modules to generate compressed classes",
"main": "dist/withClassnamesMinifier.js",
"types": "dist/withClassnamesMinifier.d.ts",
Expand Down Expand Up @@ -36,6 +36,10 @@
"devDependencies": {
"@types/node": "16.11.12",
"@types/webpack": "5.28.0",
"css-loader": "6.8.1",
"typescript": "4.5.4"
},
"peerDependencies": {
"css-loader": ">=4.0.0"
}
}
4 changes: 2 additions & 2 deletions src/lib/constants/minifiers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const MINIFIED = 'minified';
export const DETAILED = 'detailed';
export const NONE = 'none';
export const VALID_MINIFIERS_KEYS = [MINIFIED, DETAILED, NONE] as const;
export const CUSTOM = 'custom';
export const VALID_MINIFIERS_KEYS = [MINIFIED, NONE, CUSTOM] as const;
4 changes: 2 additions & 2 deletions src/lib/converters/ConverterBase.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { LoaderContext } from 'webpack/types';

abstract class BaseConverter {
cache: {[resource: string]: {[className: string]: string}} = {};
cache: { [resource: string]: { [className: string]: string } } = {};

abstract getLocalIdent({ resourcePath }: LoaderContext<any>, _localIdent: string, origName: string): string;
abstract getLocalIdent({ resourcePath }: LoaderContext<any>, _localIdent: string, origName: string, options: unknown): string;
};

export default BaseConverter;
Loading

0 comments on commit d0a63b1

Please sign in to comment.