@nimpl/classnames-minifier 0.0.0-experimental-4338750
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 +21 -0
- package/README.md +23 -0
- package/dist/lib/injectConfig.d.ts +8 -0
- package/dist/lib/injectConfig.js +44 -0
- package/dist/withClassnamesMinifier.d.ts +6 -0
- package/dist/withClassnamesMinifier.js +41 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Alex Savelyev <dev@alexdln.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# @nimpl/classnames-minifier
|
|
2
|
+
|
|
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
|
+
|
|
5
|
+
Visit https://nimpl.dev/docs/classnames-minifier to view the full documentation.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
**Using npm:**
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm i @nimpl/classnames-minifier
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
**Using yarn:**
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
yarn add @nimpl/classnames-minifier
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## License
|
|
22
|
+
|
|
23
|
+
[MIT](https://github.com/alexdln/nimpl-classnames-minifier/blob/main/LICENSE)
|
|
@@ -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,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const injectConfig = (config, rules) => {
|
|
4
|
+
var _a;
|
|
5
|
+
if (!rules)
|
|
6
|
+
return;
|
|
7
|
+
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");
|
|
8
|
+
if (oneOfRule && typeof oneOfRule === "object") {
|
|
9
|
+
const testCssLoaderWithModules = (loaderObj) => {
|
|
10
|
+
var _a;
|
|
11
|
+
return typeof loaderObj === "object" &&
|
|
12
|
+
((_a = loaderObj === null || loaderObj === void 0 ? void 0 : loaderObj.loader) === null || _a === void 0 ? void 0 : _a.match("css-loader")) &&
|
|
13
|
+
typeof loaderObj.options === "object" &&
|
|
14
|
+
loaderObj.options.modules;
|
|
15
|
+
};
|
|
16
|
+
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")); };
|
|
17
|
+
(_a = oneOfRule.oneOf) === null || _a === void 0 ? void 0 : _a.forEach((rule) => {
|
|
18
|
+
if (rule && Array.isArray(rule.use)) {
|
|
19
|
+
let cssLoaderIndex = null;
|
|
20
|
+
for (let i = rule.use.length - 1; i >= 0; i--) {
|
|
21
|
+
const loaderObj = rule.use[i];
|
|
22
|
+
if (!loaderObj)
|
|
23
|
+
continue;
|
|
24
|
+
/**
|
|
25
|
+
* Next.js has special logic for generating font classes,
|
|
26
|
+
* so we don't change the rules that work with fonts and, as a result, do not minify font classes
|
|
27
|
+
*/
|
|
28
|
+
if (testFontLoader(loaderObj))
|
|
29
|
+
break;
|
|
30
|
+
if (testCssLoaderWithModules(loaderObj)) {
|
|
31
|
+
if (typeof loaderObj !== "object" || typeof loaderObj.options !== "object")
|
|
32
|
+
continue;
|
|
33
|
+
cssLoaderIndex = i;
|
|
34
|
+
loaderObj.options.modules.getLocalIdent = config.classnamesMinifier.getLocalIdent;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (cssLoaderIndex !== null) {
|
|
38
|
+
rule.use.splice(cssLoaderIndex, 1, config.classnamesMinifier.postLoader, rule.use[cssLoaderIndex], config.classnamesMinifier.preLoader);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
exports.default = injectConfig;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Config } from "classnames-minifier/dist/lib/types/plugin";
|
|
2
|
+
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,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const classnames_minifier_1 = __importDefault(require("classnames-minifier"));
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const injectConfig_1 = __importDefault(require("./lib/injectConfig"));
|
|
10
|
+
let classnamesMinifier;
|
|
11
|
+
const withClassnameMinifier = (pluginOptions = {}) => {
|
|
12
|
+
return (nextConfig = {}) => {
|
|
13
|
+
if (pluginOptions.disabled)
|
|
14
|
+
return nextConfig;
|
|
15
|
+
if (!classnamesMinifier) {
|
|
16
|
+
const distDir = (nextConfig === null || nextConfig === void 0 ? void 0 : nextConfig.distDir) || ".next";
|
|
17
|
+
const distDirAbsolute = path_1.default.join(process.cwd(), distDir);
|
|
18
|
+
const cacheDir = path_1.default.join(distDirAbsolute, "cache/ncm");
|
|
19
|
+
classnamesMinifier = new classnames_minifier_1.default({
|
|
20
|
+
prefix: pluginOptions.prefix,
|
|
21
|
+
reservedNames: pluginOptions.reservedNames,
|
|
22
|
+
distDeletionPolicy: pluginOptions.distDeletionPolicy,
|
|
23
|
+
experimental: pluginOptions.experimental,
|
|
24
|
+
distDir: distDirAbsolute,
|
|
25
|
+
checkDistFreshness: () => {
|
|
26
|
+
return !fs_1.default.existsSync(".next/build-manifest.json");
|
|
27
|
+
},
|
|
28
|
+
cacheDir,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return Object.assign(Object.assign({}, nextConfig), { webpack: (config, options) => {
|
|
32
|
+
var _a;
|
|
33
|
+
(0, injectConfig_1.default)({ classnamesMinifier }, (_a = config.module) === null || _a === void 0 ? void 0 : _a.rules);
|
|
34
|
+
if (typeof nextConfig.webpack === "function") {
|
|
35
|
+
return nextConfig.webpack(config, options);
|
|
36
|
+
}
|
|
37
|
+
return config;
|
|
38
|
+
} });
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
exports.default = withClassnameMinifier;
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nimpl/classnames-minifier",
|
|
3
|
+
"version": "0.0.0-experimental-4338750",
|
|
4
|
+
"description": "Library for configuring style modules to generate compressed classes",
|
|
5
|
+
"main": "dist/withClassnamesMinifier.js",
|
|
6
|
+
"types": "dist/withClassnamesMinifier.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"next",
|
|
15
|
+
"next.js",
|
|
16
|
+
"classname",
|
|
17
|
+
"class",
|
|
18
|
+
"minify",
|
|
19
|
+
"compress",
|
|
20
|
+
"cut",
|
|
21
|
+
"css",
|
|
22
|
+
"sass",
|
|
23
|
+
"scss",
|
|
24
|
+
"modules"
|
|
25
|
+
],
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git://github.com/alexdln/nimpl-classnames-minifier.git"
|
|
29
|
+
},
|
|
30
|
+
"author": {
|
|
31
|
+
"name": "Alex Savelyev",
|
|
32
|
+
"email": "dev@alexdln.com",
|
|
33
|
+
"url": "https://github.com/alexdln/"
|
|
34
|
+
},
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/node": "25.0.3",
|
|
38
|
+
"@types/uuid": "11.0.0",
|
|
39
|
+
"@types/webpack": "5.28.5",
|
|
40
|
+
"css-loader": "7.1.2",
|
|
41
|
+
"typescript": "5.9.3"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"css-loader": ">=4.0.0"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"classnames-minifier": "1.0.0",
|
|
48
|
+
"uuid": "13.0.0"
|
|
49
|
+
}
|
|
50
|
+
}
|