Переглянути джерело

[icon] Change rollup-plugin-stdf-icon

dufu1991 3 роки тому
батько
коміт
b1ce11650d

+ 17 - 15
packages/rollup-plugin-stdf-icon/README.md

@@ -3,7 +3,7 @@
 
 # Introduction
 
-This is a Rollup plugin for [STDF](https://stdf.design) project that combines all SVG files in a specified folder into a single [SVG symbol](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/symbol). It can be used in both Rollup and Vite projects, including Vue and React projects created with Vite.
+This is a Rollup plugin that combines all SVG files in specified folders (supports multiple) into a single [SVG symbol](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/symbol) for use in [STDF](https://stdf.design) projects. It is compatible with Vite and can be used in Vue or React projects created with Vite.
 
 For more information about the STDF Icon component, please refer to the [Icon Guide](https://stdf.design/#/components?nav=icon&tab=2).
 
@@ -27,13 +27,13 @@ Configure the plugin in vite.config.js or vite.config.ts:
 
 ```js
 // ...
-import symbol from 'rollup-plugin-stdf-icon';
+import svgSprite from 'rollup-plugin-stdf-icon';
 
 export default defineConfig({
     // ...
     plugins:[
         // ...
-        symbol(),
+        svgSprite(),
         // ...
     ]
     // ...
@@ -42,28 +42,30 @@ export default defineConfig({
 
 During development, simply place the SVG files you need in the specified input folder (default: `src/assets/svgs`). The plugin will automatically combine them into a single SVG symbol file and output it to the specified output folder (default: `public/fonts`). After building with Vite, the files in the public folder will be copied to the dist folder. Therefore, after building, the combined SVG symbol file will be located in the dist/fonts folder. Please refer to the [Vite Asset Handling](https://vitejs.dev/guide/assets.html#the-public-directory) documentation.
 
-If you need to modify the input/output folders and the filename of the combined file, you can customize the configuration in vite.config.js or vite.config.ts:
+Generally, you can simply place the SVG files in the default input folder without the need for additional configuration.
+
+If you need to modify the input/output folders and the filename of the combined file, or if you need to combine multiple folders, you can customize the configuration in vite.config.js or vite.config.ts:
 
 ```js
 // ...
-symbol({
-    inFile: 'src/assets/icons',
-    outFile: 'public/icons',
-    fileName: 'sprite'
-}),
+    svgSprite([
+        { inFile: 'src/assets/svgs', outFile: 'public/fonts', fileName: 'symbol' },
+        { inFile: 'src/assets/icons', outFile: 'public/fonts', fileName: 'icon' },
+    ]),
 // ...
 ```
 
-The combined sprite.svg file will be outputted to public/icons/sprite.svg. **In this case, please update the path in the STDF Icon Props to `/icons/sprite.svg`**
+This configuration will combine two symbols. **When using the STDF Icon component, please update the path to the corresponding `fonts/symbol.svg` or `fonts/icon.svg`**.
 
+Note: **The parameter should be an array** representing the configuration for multiple folders. **Each folder configuration should be an object** with `inFile` as the folder where the SVG files to be combined are located, `outFile` as the output path for the combined SVG symbol file, and `fileName` as the filename of the combined SVG symbol file. Please ensure the correctness and avoid conflicts in paths and filenames.
 
 # Configuration
 
-| Parameter | Default         | Description                                                  |
-| --------- | --------------- | ------------------------------------------------------------ |
-| inFile    | src/assets/svgs | The folder where all the SVG files to be merged are located. |
-| outFile   | public/fonts    | The output path for the merged SVG symbol file.              |
-| fileName  | symbol          | The filename of the merged SVG symbol file.                  |
+| Parameter | Default            | Description                                   |
+| --------- | ------------------ | --------------------------------------------- |
+| inFile    | src/assets/svgs   | The folder where all the SVG files to be merged are located. |
+| outFile   | public/fonts      | The output path for the merged SVG symbol file. |
+| fileName  | symbol             | The filename of the merged SVG symbol file.    |
 
 # License
 

+ 12 - 11
packages/rollup-plugin-stdf-icon/README_CN.md

@@ -2,7 +2,7 @@
 
 # 介绍
 
-将指定文件夹内的所有 SVG 组合为一个 [SVG symbol](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/symbol),以在 [STDF](https://stdf.design) 项目中使用的 Rollup 插件,当然也支持在 Vite 项目中使用。也支持基于 Vite 创建的 Vue 和 React 项目。
+一个 Rolup 插件,将指定文件夹(支持多个)内的所有 SVG 组合为一个 [SVG symbol](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/symbol),以在 [STDF](https://stdf.design) 项目中使用。兼容 Vite,也可用于 Vite 创建的 Vue 或 React 项目。
 
 关于 STDF 的 Icon 组件,请参考 [Icon 指南](https://stdf.design/#/components?nav=icon&tab=2)。
 
@@ -26,13 +26,13 @@ npm i rollup-plugin-stdf-icon -D
 
 ```js
 // ...
-import symbol from 'rollup-plugin-stdf-icon';
+import svgSprite from 'rollup-plugin-stdf-icon';
 
 export default defineConfig({
     // ...
     plugins:[
         // ...
-        symbol(),
+        svgSprite(),
         // ...
     ]
     // ...
@@ -41,20 +41,21 @@ export default defineConfig({
 
 开发过程中只需要将用到的 svg 文件放到指定的入口文件夹(默认 `src/assets/svgs`),插件会自动将其合并为一个 SVG symbol 文件,输出到指定的输出文件夹(默认 `public/fonts`)。Vite 构建之后 public 文件夹下的文件会被复制到 dist 文件夹下,所以在构建之后,合并的 SVG symbol 文件会出现在 dist/fonts 文件夹下。请参考 [Vite 配置](https://cn.vitejs.dev/guide/assets.html#the-public-directory)。
 
-如果需要修改输入输出文件夹以及合并的文件名,可以在 vite.config.js 或 vite.config.ts 中修改配置:
+一般来说,按照默认配置将 svg 文件放到入口文件夹即可,无需过多配置。
+
+如果需要修改输入输出文件夹以及合并的文件名,或者同时需要合并多个文件夹,可以在 vite.config.js 或 vite.config.ts 中修改配置:
 
 ```js
 // ...
-symbol({
-    inFile: 'src/assets/icons',
-    outFile: 'public/icons',
-    fileName: 'sprite'
-}),
+    svgSprite([
+        { inFile: 'src/assets/svgs', outFile: 'public/fonts', fileName: 'symbol' },
+        { inFile: 'src/assets/icons', outFile: 'public/fonts', fileName: 'icon' },
+    ]),
 // ...
 ```
+此配置会合并两个 symbol。**此时使用 STDF 的 Icon 组件时,请配合修改 path 为对应的 `fonts/symbol.svg` 或 `fonts/icon.svg`**
 
-合并的 sprite.svg 文件将输出到 public/icons/sprite.svg。**此时请修改 STDF Icon Props 的 path 为对应的 `/icons/sprite.svg`**
-
+注意:**传入参数为数组**,表示多个文件夹的配置。**每个文件夹的配置为一个对象**,对象中的 inFile 为将要被合并的 SVG 文件所在的文件夹,outFile 为合并后的 SVG symbol 文件的输出路径,fileName 为合并后的 SVG symbol 文件的文件名。请注意路径与文件名的正确性与冲突。
 
 # 配置
 

+ 0 - 3
packages/rollup-plugin-stdf-icon/index.js

@@ -1,3 +0,0 @@
-#!/usr/bin/env node
-
-import './dist/index.js';

+ 4 - 2
packages/rollup-plugin-stdf-icon/package.json

@@ -1,8 +1,8 @@
 {
     "name": "rollup-plugin-stdf-icon",
-    "version": "0.0.1",
+    "version": "0.0.2",
     "description": "A Rollup plugin that combines a series of svg into one symbol for use in the STDF project",
-    "main": "index.js",
+    "main": "dist/index.js",
     "scripts": {
         "build": "rollup -c",
         "test": "echo \"Error: no test specified\" && exit 1"
@@ -25,6 +25,8 @@
         "node": ">=14.14"
     },
     "dependencies": {
+        "cheerio": "1.0.0-rc.12",
+        "crypto": "^1.0.1",
         "fs-extra": "^11.1.1",
         "svgo": "^3.0.2",
         "svgstore": "^3.0.1"

+ 1 - 1
packages/rollup-plugin-stdf-icon/rollup.config.js

@@ -4,5 +4,5 @@ export default {
     input: 'src/index.js',
     output: [{ file: 'dist/index.js', format: 'es' }],
     external: ['fs-extra', 'svgo', 'svgstore'],
-    plugins: [terser()],
+    plugins: [terser({ keep_fnames: true })],
 };