vite-plugin-material-symbols 0.0.2
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 +62 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Anna Bocharova
|
|
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,62 @@
|
|
|
1
|
+
# vite-plugin-material-symbols
|
|
2
|
+
|
|
3
|
+
[](https://coveralls.io/github/RobinTail/vite-plugin-material-symbols)
|
|
4
|
+
|
|
5
|
+
The plugin determines which Material Symbols are used in JSX `<Icon>` tags and substitutes this list in `index.html`
|
|
6
|
+
for selective download from Google CDN, thus reducing the volume of the font downloaded by the user.
|
|
7
|
+
|
|
8
|
+
## Demo
|
|
9
|
+
|
|
10
|
+
Consider a sample React component using MUI Icon:
|
|
11
|
+
|
|
12
|
+
```tsx
|
|
13
|
+
import Stack from "@mui/material/Stack";
|
|
14
|
+
import Icon from "@mui/material/Icon";
|
|
15
|
+
|
|
16
|
+
const Component = () => (
|
|
17
|
+
<Stack gap={2}>
|
|
18
|
+
<Icon>home</Icon>
|
|
19
|
+
<Icon>chevron_right</Icon>
|
|
20
|
+
<Icon>comment</Icon>
|
|
21
|
+
</Stack>
|
|
22
|
+
);
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
And the Material Symbols linked within `index.html` having `__MATERIAL_SYMBOLS__` placeholder:
|
|
26
|
+
|
|
27
|
+
```html
|
|
28
|
+
<!doctype html>
|
|
29
|
+
<html lang="en">
|
|
30
|
+
<head>
|
|
31
|
+
<link
|
|
32
|
+
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0,0&__MATERIAL_SYMBOLS__"
|
|
33
|
+
rel="stylesheet"
|
|
34
|
+
/>
|
|
35
|
+
</head>
|
|
36
|
+
<body>
|
|
37
|
+
<div id="root"></div>
|
|
38
|
+
<script type="module" src="/src/index.tsx"></script>
|
|
39
|
+
</body>
|
|
40
|
+
</html>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Configuring Vite to use the plugin:
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import { defineConfig } from "vite";
|
|
47
|
+
import react from "@vitejs/plugin-react-swc";
|
|
48
|
+
import materialSymbols from "vite-plugin-material-symbols";
|
|
49
|
+
|
|
50
|
+
export default defineConfig({
|
|
51
|
+
plugins: [react(), materialSymbols()],
|
|
52
|
+
});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
After running `vite build`, that link will have the substituted list of sorted icon names:
|
|
56
|
+
|
|
57
|
+
```html
|
|
58
|
+
<link
|
|
59
|
+
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0,0&icon_names=chevron_right,comment,home"
|
|
60
|
+
rel="stylesheet"
|
|
61
|
+
/>
|
|
62
|
+
```
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import esquery from "esquery";const plugin=()=>{const d=new Set();return {name:"material-symbols",enforce:"pre",moduleParsed:function({id:e,ast:f}){if(!f)return;const g=esquery.query(f,"CallExpression[callee.name='jsx'][arguments.0.name='Icon'] > .arguments > Property[key.name='children'] Literal");this.debug({id:e,message:"value"});for(const {value:h}of g)if(typeof h==="string")d.add(h)},transformIndexHtml:(e)=>e.replace("__MATERIAL_SYMBOLS__",d.size?`icon_names=${Array.from(d.values()).toSorted().join(",")}`:"")}};var src_default=plugin;export {src_default as default};
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vite-plugin-material-symbols",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "Selective loading of Material Symbols for production",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+ssh://git@github.com/RobinTail/vite-plugin-material-symbols.git"
|
|
9
|
+
},
|
|
10
|
+
"author": "Robin Tail <robin_tail@me.com>",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"type": "module",
|
|
13
|
+
"scripts": {
|
|
14
|
+
"lint": "bun run biome check",
|
|
15
|
+
"prebuild": "tsc --noEmit",
|
|
16
|
+
"build": "tsdown",
|
|
17
|
+
"postbuild": "attw --pack --profile esm-only",
|
|
18
|
+
"mdfix": "bunx --bun prettier *.md --write"
|
|
19
|
+
},
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"default": "./dist/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"files": ["dist", "*.md"],
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"vite": "^6.0.0"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"esquery": "^1.6.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@arethetypeswrong/cli": "^0.17.0",
|
|
35
|
+
"@biomejs/biome": "1.9.4",
|
|
36
|
+
"@tsconfig/bun": "^1.0.7",
|
|
37
|
+
"@types/bun": "^1.1.14",
|
|
38
|
+
"@types/esquery": "^1.5.4",
|
|
39
|
+
"tsdown": "^0.3.1",
|
|
40
|
+
"typescript": "^5.7.2"
|
|
41
|
+
}
|
|
42
|
+
}
|