@nimpl/classnames-minifier 4.0.1 → 4.1.1
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 +1 -1
- package/README.md +20 -3
- package/dist/{withClassnamesMinifier.d.ts → cjs/withClassnamesMinifier.d.ts} +2 -2
- package/dist/{withClassnamesMinifier.js → cjs/withClassnamesMinifier.js} +20 -2
- package/dist/esm/lib/injectConfig.d.ts +8 -0
- package/dist/esm/lib/injectConfig.js +42 -0
- package/dist/esm/withClassnamesMinifier.d.ts +6 -0
- package/dist/esm/withClassnamesMinifier.js +54 -0
- package/package.json +25 -14
- /package/dist/{lib → cjs/lib}/injectConfig.d.ts +0 -0
- /package/dist/{lib → cjs/lib}/injectConfig.js +0 -0
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2021
|
|
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
|
@@ -7,15 +7,32 @@ Visit https://nimpl.dev/docs/classnames-minifier to view the full documentation.
|
|
|
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
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { type NextConfig } from "next";
|
|
19
|
+
import classNamesMinifier from "@nimpl/classnames-minifier";
|
|
20
|
+
|
|
21
|
+
const withClassNamesMinifier = classNamesMinifier({
|
|
22
|
+
/* plugin options here */
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const nextConfig: NextConfig = withClassNamesMinifier({
|
|
26
|
+
/* next options here */
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export default nextConfig;
|
|
30
|
+
```
|
|
31
|
+
|
|
15
32
|
```bash
|
|
16
|
-
|
|
33
|
+
npm run build --webpack
|
|
17
34
|
```
|
|
18
35
|
|
|
19
36
|
## License
|
|
20
37
|
|
|
21
|
-
[MIT](https://github.com/
|
|
38
|
+
[MIT](https://github.com/alexdln/nimpl-classnames-minifier/blob/main/LICENSE)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Config } from "classnames-minifier
|
|
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;
|
|
@@ -8,10 +8,25 @@ const path_1 = __importDefault(require("path"));
|
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
9
|
const injectConfig_1 = __importDefault(require("./lib/injectConfig"));
|
|
10
10
|
let classnamesMinifier;
|
|
11
|
+
const isTurbopackEnabled = (nextConfig) => {
|
|
12
|
+
var _a;
|
|
13
|
+
if (((_a = nextConfig === null || nextConfig === void 0 ? void 0 : nextConfig.experimental) === null || _a === void 0 ? void 0 : _a.turbo) || (nextConfig === null || nextConfig === void 0 ? void 0 : nextConfig.turbopack)) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
if (process.env.NEXT_PRIVATE_TURBO === "1" || process.env.TURBOPACK != null || process.argv.includes("--turbo")) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
};
|
|
11
21
|
const withClassnameMinifier = (pluginOptions = {}) => {
|
|
12
22
|
return (nextConfig = {}) => {
|
|
13
23
|
if (pluginOptions.disabled)
|
|
14
24
|
return nextConfig;
|
|
25
|
+
const turbopackEnabled = isTurbopackEnabled(nextConfig);
|
|
26
|
+
if (turbopackEnabled) {
|
|
27
|
+
console.warn("classnames-minifier is disabled in turbopack mode. Please run the process with `--webpack` flag");
|
|
28
|
+
return nextConfig;
|
|
29
|
+
}
|
|
15
30
|
if (!classnamesMinifier) {
|
|
16
31
|
const distDir = (nextConfig === null || nextConfig === void 0 ? void 0 : nextConfig.distDir) || ".next";
|
|
17
32
|
const distDirAbsolute = path_1.default.join(process.cwd(), distDir);
|
|
@@ -28,14 +43,17 @@ const withClassnameMinifier = (pluginOptions = {}) => {
|
|
|
28
43
|
cacheDir,
|
|
29
44
|
});
|
|
30
45
|
}
|
|
31
|
-
return
|
|
46
|
+
return {
|
|
47
|
+
...nextConfig,
|
|
48
|
+
webpack: (config, options) => {
|
|
32
49
|
var _a;
|
|
33
50
|
(0, injectConfig_1.default)({ classnamesMinifier }, (_a = config.module) === null || _a === void 0 ? void 0 : _a.rules);
|
|
34
51
|
if (typeof nextConfig.webpack === "function") {
|
|
35
52
|
return nextConfig.webpack(config, options);
|
|
36
53
|
}
|
|
37
54
|
return config;
|
|
38
|
-
}
|
|
55
|
+
},
|
|
56
|
+
};
|
|
39
57
|
};
|
|
40
58
|
};
|
|
41
59
|
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,54 @@
|
|
|
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 isTurbopackEnabled = (nextConfig) => {
|
|
7
|
+
var _a;
|
|
8
|
+
if (((_a = nextConfig === null || nextConfig === void 0 ? void 0 : nextConfig.experimental) === null || _a === void 0 ? void 0 : _a.turbo) || (nextConfig === null || nextConfig === void 0 ? void 0 : nextConfig.turbopack)) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
if (process.env.NEXT_PRIVATE_TURBO === "1" || process.env.TURBOPACK != null || process.argv.includes("--turbo")) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
return false;
|
|
15
|
+
};
|
|
16
|
+
const withClassnameMinifier = (pluginOptions = {}) => {
|
|
17
|
+
return (nextConfig = {}) => {
|
|
18
|
+
if (pluginOptions.disabled)
|
|
19
|
+
return nextConfig;
|
|
20
|
+
const turbopackEnabled = isTurbopackEnabled(nextConfig);
|
|
21
|
+
if (turbopackEnabled) {
|
|
22
|
+
console.warn("classnames-minifier is disabled in turbopack mode. Please run the process with `--webpack` flag");
|
|
23
|
+
return nextConfig;
|
|
24
|
+
}
|
|
25
|
+
if (!classnamesMinifier) {
|
|
26
|
+
const distDir = (nextConfig === null || nextConfig === void 0 ? void 0 : nextConfig.distDir) || ".next";
|
|
27
|
+
const distDirAbsolute = path.join(process.cwd(), distDir);
|
|
28
|
+
const cacheDir = path.join(distDirAbsolute, "cache/ncm");
|
|
29
|
+
classnamesMinifier = new ClassnamesMinifier({
|
|
30
|
+
prefix: pluginOptions.prefix,
|
|
31
|
+
reservedNames: pluginOptions.reservedNames,
|
|
32
|
+
distDeletionPolicy: pluginOptions.distDeletionPolicy,
|
|
33
|
+
experimental: pluginOptions.experimental,
|
|
34
|
+
distDir: distDirAbsolute,
|
|
35
|
+
checkDistFreshness: () => {
|
|
36
|
+
return !fs.existsSync(".next/build-manifest.json");
|
|
37
|
+
},
|
|
38
|
+
cacheDir,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
...nextConfig,
|
|
43
|
+
webpack: (config, options) => {
|
|
44
|
+
var _a;
|
|
45
|
+
injectConfig({ classnamesMinifier }, (_a = config.module) === null || _a === void 0 ? void 0 : _a.rules);
|
|
46
|
+
if (typeof nextConfig.webpack === "function") {
|
|
47
|
+
return nextConfig.webpack(config, options);
|
|
48
|
+
}
|
|
49
|
+
return config;
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
export default withClassnameMinifier;
|
package/package.json
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nimpl/classnames-minifier",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.1",
|
|
4
4
|
"description": "Library for configuring style modules to generate compressed classes",
|
|
5
|
-
"main": "dist/withClassnamesMinifier.js",
|
|
6
|
-
"
|
|
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": "
|
|
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/
|
|
39
|
+
"url": "git://github.com/alexdln/nimpl-classnames-minifier.git"
|
|
29
40
|
},
|
|
30
41
|
"author": {
|
|
31
|
-
"name": "Savelyev
|
|
32
|
-
"email": "
|
|
33
|
-
"url": "https://github.com/
|
|
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": "
|
|
38
|
-
"@types/uuid": "
|
|
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.
|
|
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": "
|
|
48
|
-
"uuid": "
|
|
58
|
+
"classnames-minifier": "*",
|
|
59
|
+
"uuid": "13.0.0"
|
|
49
60
|
}
|
|
50
|
-
}
|
|
61
|
+
}
|
|
File without changes
|
|
File without changes
|