vite-plugin-lucide-preprocess 1.0.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 +19 -0
- package/README.md +52 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +41 -0
- package/dist/index.js.map +1 -0
- package/package.json +48 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2024 WarningImHack3r <43064022+WarningImHack3r@users.noreply.github.com>
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# vite-plugin-lucide-preprocess
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+

|
|
7
|
+
|
|
8
|
+
A [Vite](https://vitejs.dev) plugin to replace imports for [Lucide icons](https://lucide.dev).
|
|
9
|
+
|
|
10
|
+
## What is this?
|
|
11
|
+
|
|
12
|
+
This plugin is a follow-up to [this PR on Lucide](https://github.com/lucide-icons/lucide/pull/1707).
|
|
13
|
+
If you want to import Lucide icons in your project, you can use two methods:
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import { IconName } from "lucide-svelte";
|
|
17
|
+
// or, since PR #1707 (at least for lucide-svelte):
|
|
18
|
+
import IconName from "lucide-svelte/icons/icon-name";
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
While the first method is more convenient (and may be the one used by auto-import features in your editor), it is not tree-shakeable. In fact, a single import from `"lucide-<library>"` will import all icons, which is not ideal for performance.
|
|
22
|
+
|
|
23
|
+
This plugin will replace the first method with the second one, so you can keep the convenience of the first method while benefiting from tree-shaking optimizations. “Correct” imports will be kept as-is.
|
|
24
|
+
|
|
25
|
+
> [!NOTE]
|
|
26
|
+
> It is primarily intended for `lucide-svelte`, but it should work with any Lucide package using Vite, if they follow the same structure.
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
Install the plugin with your package manager of choice:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pnpm i -D vite-plugin-lucide-preprocess
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Then, add it to your `vite.config.js`/`.ts`:
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
import { defineConfig } from "vite";
|
|
40
|
+
import lucidePreprocess from "vite-plugin-lucide-preprocess";
|
|
41
|
+
|
|
42
|
+
export default defineConfig({
|
|
43
|
+
plugins: [lucidePreprocess(), ...]
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
> [!WARNING]
|
|
48
|
+
> Make sure to add the plugin **before** any other preprocessors in the `plugins` array.
|
|
49
|
+
|
|
50
|
+
## License
|
|
51
|
+
|
|
52
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AAEA;;;GAGG;AACH,oCAFY,OAAO,MAAM,EAAE,MAAM,CAyChC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const ignoredPaths = ["/node_modules/", "/.svelte-kit/"];
|
|
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.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
|
+
}
|
|
41
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AAAA,MAAM,YAAY,GAAG,CAAC,gBAAgB,EAAE,eAAe,CAAC,CAAC;AAEzD;;;GAGG;AACH,MAAM,CAAC,OAAO;IACb,OAAO;QACN,IAAI,EAAE,+BAA+B;QACrC,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;YACzB,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC9C,OAAO;YACR,CAAC;YACD,OAAO;gBACN,IAAI,EAAE,IAAI,CAAC,OAAO,CACjB,kEAAkE;gBAClE;;;;;;;;mBAQG;gBACH,CAAC,CAAC,EAAE,cAAc,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,EAAE;oBAC/D,MAAM,OAAO,GAAG,UAAU;yBACxB,KAAK,CAAC,GAAG,CAAC;yBACV,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;yBAClB,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;oBACrC,OAAO,OAAO;yBACZ,GAAG,CAAC,CAAC,CAAC,EAAE;wBACR,MAAM,YAAY,GAAG,CAAC,CAAC,OAAO,CAC7B,QAAQ,EACR,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,WAAW,EAAE,CAChE,CAAC;wBACF,OAAO,GAAG,cAAc,UAAU,CAAC,SAAS,KAAK,UAAU,SAAS,UAAU,YAAY,GAAG,KAAK,GAAG,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC;oBAC7H,CAAC,CAAC;yBACD,IAAI,CAAC,IAAI,CAAC,CAAC;gBACd,CAAC,CACD;aACD,CAAC;QACH,CAAC;KACD,CAAC;AACH,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vite-plugin-lucide-preprocess",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"author": {
|
|
5
|
+
"url": "https://github.com/WarningImHack3r",
|
|
6
|
+
"name": "WarningImHack3r"
|
|
7
|
+
},
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/WarningImHack3r/vite-plugin-lucide-preprocess"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"vite",
|
|
15
|
+
"vite-plugin",
|
|
16
|
+
"lucide",
|
|
17
|
+
"preprocessor"
|
|
18
|
+
],
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"default": "./dist/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"!dist/**/*.test.*",
|
|
28
|
+
"!dist/**/*.spec.*"
|
|
29
|
+
],
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"vite": "^5"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"prettier": "^3.3.3",
|
|
35
|
+
"publint": "^0.2.9",
|
|
36
|
+
"typescript": "^5.5.4",
|
|
37
|
+
"vite": "^5.4.0"
|
|
38
|
+
},
|
|
39
|
+
"main": "./dist/index.js",
|
|
40
|
+
"types": "./dist/index.d.ts",
|
|
41
|
+
"type": "module",
|
|
42
|
+
"scripts": {
|
|
43
|
+
"dev": "tsc -w",
|
|
44
|
+
"build": "tsc",
|
|
45
|
+
"lint": "prettier --check . && publint",
|
|
46
|
+
"format": "prettier --write ."
|
|
47
|
+
}
|
|
48
|
+
}
|