@nimpl/classnames-minifier 4.0.0 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 Alexander Savelyev <vordgi1@gmail.com>
3
+ Copyright (c) 2021 Alex Savelyev <dev@alexdln.com>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -2,20 +2,22 @@
2
2
 
3
3
  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. The package itself synchronizes minified classnames with components of the application compiled earlier.
4
4
 
5
- Visit https://nimpl.tech/classnames-minifier to view the full documentation.
5
+ Visit https://nimpl.dev/docs/classnames-minifier to view the full documentation.
6
6
 
7
7
  ## Installation
8
8
 
9
9
  **Using npm:**
10
+
10
11
  ```bash
11
12
  npm i @nimpl/classnames-minifier
12
13
  ```
13
14
 
14
15
  **Using yarn:**
16
+
15
17
  ```bash
16
18
  yarn add @nimpl/classnames-minifier
17
19
  ```
18
20
 
19
21
  ## License
20
22
 
21
- [MIT](https://github.com/vordgi/nimpl-classnames-minifier/blob/main/LICENSE)
23
+ [MIT](https://github.com/alexdln/nimpl-classnames-minifier/blob/main/LICENSE)
@@ -1,5 +1,5 @@
1
- import type { Config } from "classnames-minifier/dist/lib/types/plugin";
2
- type PluginOptions = Omit<Config, "cacheDir" | "distDir" | "checkDistFreshness"> & {
1
+ import type { Config } from "classnames-minifier";
2
+ export type PluginOptions = Omit<Config, "cacheDir" | "distDir" | "checkDistFreshness"> & {
3
3
  disabled?: boolean;
4
4
  };
5
5
  declare const withClassnameMinifier: (pluginOptions?: PluginOptions) => (nextConfig?: any) => any;
@@ -28,14 +28,17 @@ const withClassnameMinifier = (pluginOptions = {}) => {
28
28
  cacheDir,
29
29
  });
30
30
  }
31
- return Object.assign(Object.assign({}, nextConfig), { webpack: (config, options) => {
31
+ return {
32
+ ...nextConfig,
33
+ webpack: (config, options) => {
32
34
  var _a;
33
35
  (0, injectConfig_1.default)({ classnamesMinifier }, (_a = config.module) === null || _a === void 0 ? void 0 : _a.rules);
34
36
  if (typeof nextConfig.webpack === "function") {
35
37
  return nextConfig.webpack(config, options);
36
38
  }
37
39
  return config;
38
- } });
40
+ },
41
+ };
39
42
  };
40
43
  };
41
44
  exports.default = withClassnameMinifier;
@@ -0,0 +1,8 @@
1
+ import type { ModuleOptions } from "webpack";
2
+ import type ClassnamesMinifier from "classnames-minifier";
3
+ export type InjectConfig = {
4
+ localIdentName?: string;
5
+ classnamesMinifier: ClassnamesMinifier;
6
+ };
7
+ declare const injectConfig: (config: InjectConfig, rules?: ModuleOptions["rules"]) => void;
8
+ export default injectConfig;
@@ -0,0 +1,42 @@
1
+ const injectConfig = (config, rules) => {
2
+ var _a;
3
+ if (!rules)
4
+ return;
5
+ const oneOfRule = rules === null || rules === void 0 ? void 0 : rules.find((rule) => typeof rule === "object" && typeof (rule === null || rule === void 0 ? void 0 : rule.oneOf) === "object");
6
+ if (oneOfRule && typeof oneOfRule === "object") {
7
+ const testCssLoaderWithModules = (loaderObj) => {
8
+ var _a;
9
+ return typeof loaderObj === "object" &&
10
+ ((_a = loaderObj === null || loaderObj === void 0 ? void 0 : loaderObj.loader) === null || _a === void 0 ? void 0 : _a.match("css-loader")) &&
11
+ typeof loaderObj.options === "object" &&
12
+ loaderObj.options.modules;
13
+ };
14
+ const testFontLoader = (loaderObj) => { var _a; return typeof loaderObj === "object" && ((_a = loaderObj === null || loaderObj === void 0 ? void 0 : loaderObj.loader) === null || _a === void 0 ? void 0 : _a.match("next-font-loader")); };
15
+ (_a = oneOfRule.oneOf) === null || _a === void 0 ? void 0 : _a.forEach((rule) => {
16
+ if (rule && Array.isArray(rule.use)) {
17
+ let cssLoaderIndex = null;
18
+ for (let i = rule.use.length - 1; i >= 0; i--) {
19
+ const loaderObj = rule.use[i];
20
+ if (!loaderObj)
21
+ continue;
22
+ /**
23
+ * Next.js has special logic for generating font classes,
24
+ * so we don't change the rules that work with fonts and, as a result, do not minify font classes
25
+ */
26
+ if (testFontLoader(loaderObj))
27
+ break;
28
+ if (testCssLoaderWithModules(loaderObj)) {
29
+ if (typeof loaderObj !== "object" || typeof loaderObj.options !== "object")
30
+ continue;
31
+ cssLoaderIndex = i;
32
+ loaderObj.options.modules.getLocalIdent = config.classnamesMinifier.getLocalIdent;
33
+ }
34
+ }
35
+ if (cssLoaderIndex !== null) {
36
+ rule.use.splice(cssLoaderIndex, 1, config.classnamesMinifier.postLoader, rule.use[cssLoaderIndex], config.classnamesMinifier.preLoader);
37
+ }
38
+ }
39
+ });
40
+ }
41
+ };
42
+ export default injectConfig;
@@ -0,0 +1,6 @@
1
+ import type { Config } from "classnames-minifier";
2
+ export type PluginOptions = Omit<Config, "cacheDir" | "distDir" | "checkDistFreshness"> & {
3
+ disabled?: boolean;
4
+ };
5
+ declare const withClassnameMinifier: (pluginOptions?: PluginOptions) => (nextConfig?: any) => any;
6
+ export default withClassnameMinifier;
@@ -0,0 +1,39 @@
1
+ import ClassnamesMinifier from "classnames-minifier";
2
+ import path from "path";
3
+ import fs from "fs";
4
+ import injectConfig from "./lib/injectConfig";
5
+ let classnamesMinifier;
6
+ const withClassnameMinifier = (pluginOptions = {}) => {
7
+ return (nextConfig = {}) => {
8
+ if (pluginOptions.disabled)
9
+ return nextConfig;
10
+ if (!classnamesMinifier) {
11
+ const distDir = (nextConfig === null || nextConfig === void 0 ? void 0 : nextConfig.distDir) || ".next";
12
+ const distDirAbsolute = path.join(process.cwd(), distDir);
13
+ const cacheDir = path.join(distDirAbsolute, "cache/ncm");
14
+ classnamesMinifier = new ClassnamesMinifier({
15
+ prefix: pluginOptions.prefix,
16
+ reservedNames: pluginOptions.reservedNames,
17
+ distDeletionPolicy: pluginOptions.distDeletionPolicy,
18
+ experimental: pluginOptions.experimental,
19
+ distDir: distDirAbsolute,
20
+ checkDistFreshness: () => {
21
+ return !fs.existsSync(".next/build-manifest.json");
22
+ },
23
+ cacheDir,
24
+ });
25
+ }
26
+ return {
27
+ ...nextConfig,
28
+ webpack: (config, options) => {
29
+ var _a;
30
+ injectConfig({ classnamesMinifier }, (_a = config.module) === null || _a === void 0 ? void 0 : _a.rules);
31
+ if (typeof nextConfig.webpack === "function") {
32
+ return nextConfig.webpack(config, options);
33
+ }
34
+ return config;
35
+ },
36
+ };
37
+ };
38
+ };
39
+ export default withClassnameMinifier;
package/package.json CHANGED
@@ -1,14 +1,25 @@
1
1
  {
2
2
  "name": "@nimpl/classnames-minifier",
3
- "version": "4.0.0",
3
+ "version": "4.1.0",
4
4
  "description": "Library for configuring style modules to generate compressed classes",
5
- "main": "dist/withClassnamesMinifier.js",
6
- "types": "dist/withClassnamesMinifier.d.ts",
5
+ "main": "dist/cjs/withClassnamesMinifier.js",
6
+ "module": "dist/esm/withClassnamesMinifier.mjs",
7
+ "types": "dist/cjs/withClassnamesMinifier.d.ts",
7
8
  "files": [
8
9
  "dist"
9
10
  ],
10
11
  "scripts": {
11
- "build": "tsc"
12
+ "build": "pnpm run build:cjs && pnpm run build:esm",
13
+ "build:cjs": "tsc -p tsconfig.cjs.json",
14
+ "build:esm": "tsc -p tsconfig.esm.json"
15
+ },
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/cjs/withClassnamesMinifier.d.ts",
19
+ "import": "./dist/esm/withClassnamesMinifier.mjs",
20
+ "require": "./dist/cjs/withClassnamesMinifier.js",
21
+ "default": "./dist/esm/withClassnamesMinifier.mjs"
22
+ }
12
23
  },
13
24
  "keywords": [
14
25
  "next",
@@ -25,26 +36,26 @@
25
36
  ],
26
37
  "repository": {
27
38
  "type": "git",
28
- "url": "git://github.com/vordgi/nimpl-classnames-minifier.git"
39
+ "url": "git://github.com/alexdln/nimpl-classnames-minifier.git"
29
40
  },
30
41
  "author": {
31
- "name": "Savelyev Alexander",
32
- "email": "vordgi1@gmail.com",
33
- "url": "https://github.com/vordgi/"
42
+ "name": "Alex Savelyev",
43
+ "email": "dev@alexdln.com",
44
+ "url": "https://github.com/alexdln/"
34
45
  },
35
46
  "license": "MIT",
36
47
  "devDependencies": {
37
- "@types/node": "22.8.1",
38
- "@types/uuid": "10.0.0",
48
+ "@types/node": "25.0.3",
49
+ "@types/uuid": "11.0.0",
39
50
  "@types/webpack": "5.28.5",
40
51
  "css-loader": "7.1.2",
41
- "typescript": "5.6.3"
52
+ "typescript": "5.9.3"
42
53
  },
43
54
  "peerDependencies": {
44
55
  "css-loader": ">=4.0.0"
45
56
  },
46
57
  "dependencies": {
47
- "classnames-minifier": "1.0.0",
48
- "uuid": "10.0.0"
58
+ "classnames-minifier": "*",
59
+ "uuid": "13.0.0"
49
60
  }
50
- }
61
+ }
File without changes
File without changes