vite-plugin-lucide-preprocess 1.0.1 → 1.0.3
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/dist/index.d.ts +2 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -40
- package/dist/index.js.map +1 -1
- package/dist/plugin.d.ts +18 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +74 -0
- package/dist/plugin.js.map +1 -0
- package/package.json +5 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* @return {import("vite").Plugin}
|
|
4
|
-
*/
|
|
5
|
-
export default function _default(): import("vite").Plugin;
|
|
1
|
+
export default plugin;
|
|
2
|
+
import { plugin } from "./plugin.js";
|
|
6
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":";uBAAuB,aAAa"}
|
package/dist/index.js
CHANGED
|
@@ -1,41 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* The Vite plugin that preprocesses imports to optimize Lucide icons
|
|
4
|
-
* @return {import("vite").Plugin}
|
|
5
|
-
*/
|
|
6
|
-
export default function () {
|
|
7
|
-
return {
|
|
8
|
-
name: "vite-plugin-lucide-preprocess",
|
|
9
|
-
enforce: "pre",
|
|
10
|
-
transform: (code, path) => {
|
|
11
|
-
if (ignoredPaths.some(p => path.includes(p))) {
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
return {
|
|
15
|
-
code: code.replace(/^(\s*)import\s+\{([^}]*)}\s+from\s+(["'])lucide-(.*?)["'](.*)$/gm,
|
|
16
|
-
/**
|
|
17
|
-
* @param _ The whole matched string
|
|
18
|
-
* @param initialSpacing {string} The spacing before the matched import statement
|
|
19
|
-
* @param modulesStr {string} The imported icons as a raw string
|
|
20
|
-
* @param quote {string} The quote used in the import statement (either ' or ")
|
|
21
|
-
* @param framework {string} The framework the icons are imported for
|
|
22
|
-
* @param lineEnding {string} The end of the line of the matched import statement (often a semicolon)
|
|
23
|
-
* @return The optimized import statement(s)
|
|
24
|
-
*/
|
|
25
|
-
(_, initialSpacing, modulesStr, quote, framework, lineEnding) => {
|
|
26
|
-
const modules = modulesStr
|
|
27
|
-
.split(",")
|
|
28
|
-
.map(m => m.trim())
|
|
29
|
-
.filter(m => !!m && !m.startsWith("type"));
|
|
30
|
-
return modules
|
|
31
|
-
.map(m => {
|
|
32
|
-
const dashedModule = m.replace(/[A-Z]/g, (match, offset) => (offset > 0 ? "-" : "") + match.toLowerCase());
|
|
33
|
-
return `${initialSpacing}import ${m} from ${quote}lucide-${framework}/icons/${dashedModule}${quote}${lineEnding.trimEnd()}`;
|
|
34
|
-
})
|
|
35
|
-
.join("\n");
|
|
36
|
-
})
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
}
|
|
1
|
+
import { plugin } from "./plugin.js";
|
|
2
|
+
export default plugin;
|
|
41
3
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,eAAe,MAAM,CAAC"}
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a raw string of imported icons to a list of module names,
|
|
3
|
+
* and a list of TypeScript types
|
|
4
|
+
* @param rawModules {string} The raw string of imported icons
|
|
5
|
+
* @return {[string[], string[]]} A list containing a list of imported icons,
|
|
6
|
+
* and a list of TypeScript types
|
|
7
|
+
*/
|
|
8
|
+
export function rawModulesToLists(rawModules: string): [string[], string[]];
|
|
9
|
+
/**
|
|
10
|
+
* Converts a PascalCase icon component name to a dashed string
|
|
11
|
+
* (e.g. `IconComp` to `icon-comp`)
|
|
12
|
+
* @param component {string} The PascalCase icon component name
|
|
13
|
+
* @return {string} The dashed icon component name
|
|
14
|
+
*/
|
|
15
|
+
export function iconCompToDashed(component: string): string;
|
|
16
|
+
export const importsMatcher: RegExp;
|
|
17
|
+
export function plugin(): import("vite").Plugin;
|
|
18
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.js"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,8CAJsB,MAAM,GAChB,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,CAY/B;AAED;;;;;GAKG;AACH,4CAHqB,MAAM,GACf,MAAM,CAajB;AAED,oCAAiG;AAM1F,0BAFK,OAAO,MAAM,EAAE,MAAM,CAwC/B"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const ignoredPaths = ["/node_modules/", "/.svelte-kit/"];
|
|
2
|
+
/**
|
|
3
|
+
* Converts a raw string of imported icons to a list of module names,
|
|
4
|
+
* and a list of TypeScript types
|
|
5
|
+
* @param rawModules {string} The raw string of imported icons
|
|
6
|
+
* @return {[string[], string[]]} A list containing a list of imported icons,
|
|
7
|
+
* and a list of TypeScript types
|
|
8
|
+
*/
|
|
9
|
+
export function rawModulesToLists(rawModules) {
|
|
10
|
+
const raw = rawModules
|
|
11
|
+
.split(",")
|
|
12
|
+
.map(m => m.trim())
|
|
13
|
+
.filter(m => !!m);
|
|
14
|
+
return [
|
|
15
|
+
raw.filter(m => !m.startsWith("type ")),
|
|
16
|
+
raw.filter(m => m.startsWith("type ")).map(m => m.slice(5))
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Converts a PascalCase icon component name to a dashed string
|
|
21
|
+
* (e.g. `IconComp` to `icon-comp`)
|
|
22
|
+
* @param component {string} The PascalCase icon component name
|
|
23
|
+
* @return {string} The dashed icon component name
|
|
24
|
+
*/
|
|
25
|
+
export function iconCompToDashed(component) {
|
|
26
|
+
return (component
|
|
27
|
+
.split(" ")[0] // take only the first part if there's an alias
|
|
28
|
+
// transform "IconComp" to "icon-comp"
|
|
29
|
+
.replace(/[A-Z\d]/g, (match, offset) => (offset > 0 ? "-" : "") + match.toLowerCase())
|
|
30
|
+
// fix for NxN icons
|
|
31
|
+
.replace(/(\d)x-(\d)/, (_, a, b) => `${a}x${b}`)
|
|
32
|
+
// exception for ClockNN
|
|
33
|
+
.replace(/clock-(\d)-(\d)/, (_, a, b) => `clock-${a}${b}`));
|
|
34
|
+
}
|
|
35
|
+
export const importsMatcher = /^(\s*)import\s+\{([^}]*)}\s+from\s+(["'])lucide-(.*?)["'](.*)$/gm;
|
|
36
|
+
/**
|
|
37
|
+
* The Vite plugin that preprocesses imports to optimize Lucide icons
|
|
38
|
+
* @return {import("vite").Plugin}
|
|
39
|
+
*/
|
|
40
|
+
export const plugin = () => ({
|
|
41
|
+
name: "vite-plugin-lucide-preprocess",
|
|
42
|
+
enforce: "pre",
|
|
43
|
+
transform: (code, path) => {
|
|
44
|
+
if (ignoredPaths.some(p => path.includes(p))) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
code: code.replace(importsMatcher,
|
|
49
|
+
/**
|
|
50
|
+
* @param _ The whole matched string
|
|
51
|
+
* @param initialSpacing {string} The spacing before the matched import statement
|
|
52
|
+
* @param modulesStr {string} The imported icons as a raw string
|
|
53
|
+
* @param quote {string} The quote used in the import statement (either ' or ")
|
|
54
|
+
* @param framework {string} The framework the icons are imported for
|
|
55
|
+
* @param lineEnding {string} The end of the line of the matched import statement (often a semicolon)
|
|
56
|
+
* @return The optimized import statement(s)
|
|
57
|
+
*/
|
|
58
|
+
(_, initialSpacing, modulesStr, quote, framework, lineEnding) => {
|
|
59
|
+
const [modules, types] = rawModulesToLists(modulesStr);
|
|
60
|
+
const moduleImports = modules
|
|
61
|
+
.map(m => `${initialSpacing}import ${m} from ${quote}lucide-${framework}/icons/${iconCompToDashed(m)}${quote}${lineEnding.trimEnd()}`)
|
|
62
|
+
.join(initialSpacing.includes("\n") ? "" : "\n");
|
|
63
|
+
const typesImport = `${initialSpacing}import type { ${types.join(", ")} } from ${quote}lucide-${framework}${quote}${lineEnding.trimEnd()}`;
|
|
64
|
+
return [
|
|
65
|
+
types.length ? typesImport : undefined,
|
|
66
|
+
modules.length ? moduleImports : undefined
|
|
67
|
+
]
|
|
68
|
+
.filter(Boolean)
|
|
69
|
+
.join(initialSpacing.includes("\n") ? "" : "\n");
|
|
70
|
+
})
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.js"],"names":[],"mappings":"AAAA,MAAM,YAAY,GAAG,CAAC,gBAAgB,EAAE,eAAe,CAAC,CAAC;AAEzD;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAC,UAAU;IAC3C,MAAM,GAAG,GAAG,UAAU;SACpB,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;SAClB,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACnB,OAAO;QACN,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QACvC,GAAG,CAAC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
|
"url": "https://github.com/WarningImHack3r",
|
|
6
6
|
"name": "WarningImHack3r"
|
|
@@ -31,10 +31,12 @@
|
|
|
31
31
|
"vite": "^5"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
+
"lucide-svelte": "^0.427.0",
|
|
34
35
|
"prettier": "^3.3.3",
|
|
35
36
|
"publint": "^0.2.9",
|
|
36
37
|
"typescript": "^5.5.4",
|
|
37
|
-
"vite": "^5.4.0"
|
|
38
|
+
"vite": "^5.4.0",
|
|
39
|
+
"vitest": "^2.0.5"
|
|
38
40
|
},
|
|
39
41
|
"main": "./dist/index.js",
|
|
40
42
|
"types": "./dist/index.d.ts",
|
|
@@ -42,6 +44,7 @@
|
|
|
42
44
|
"scripts": {
|
|
43
45
|
"dev": "tsc -w",
|
|
44
46
|
"build": "tsc",
|
|
47
|
+
"test": "vitest",
|
|
45
48
|
"lint": "prettier --check . && publint",
|
|
46
49
|
"format": "prettier --write ."
|
|
47
50
|
}
|