1.1.0 • Published 3 years ago

vite-plugin-svg-transform-script v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

vite-plugin-svg-transform-script

Vite based SVG information reading plug-in can read iconfont's SVG icon file. It can specify input directory, output directory Output the file name to generate a JS script file containing SVG information. Then you can use them to generate SVG icons.

install

npm i vite-plugin-svg-transform-script

use

1.Put static SVG resource file

You can directly save your SVG file into the assets / icon Folder, Of course, you can also store it in other places, just make the corresponding folder path the most parameter Just pass it on.

2.Write parameter configuration

import {transformScript} from "vite-plugin-svg-transform-script";
export default defineConfig({
  plugins: [
    transformScript({
     input:'../assets/icon/',
     output:'../dist/',
     name:'svg-dict',
     type:'js',
     format:'export'
    })
    ]
  })

3.Restart your vite project

After you have finished configuring, restart the vite project, and the plug-in will automatically read the SVG file under the input path you specified, and generate the SVG file in the output directory you specified Script file of SVG information

// svg-dict.js
export const content1 = <?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN".............. '
export const content2 = <?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN".............. '

Api

Method nameexplainparameterreturn value
transformScriptGenerate a script file based on the passed in configuration parametersISvgTransScriptOptionvoid
findSvgFileSearch SVG files in the specified folder according to the incoming parametersdir:String Svg file pathArray<{name:String,svg:String}>fileName:Humped SVG file namesvg:InnerHTML corresponding to SVG file
createFileGenerate SVG script of specified directory according to the passed in parametersoutputPath:String Specified output pathfileName:String Specified output file name svgData:Array<{name:String,svg:String} Return value of 'findSvgFile' methodvoid
loadsvgInsert the SVG element to the top of the bodysvg-dict object generated in default formatvoid

Interface

ISvgTransScriptOption

keyexplaindefault valuerequired
inputEnter the path to your SVG file-true
outputOutput path, specifying the generated file pathpath.resolve()false
nameSpecifies the name of the build file'svg-dict'false
typeSpecify the type of generated file. Please pass in 'ts' or' js''ts'false
formatSpecify the export format. Please enter 'export' or 'default''default'false

other

1.Since the script will generate variables according to the SVG file name, the file name cannot be the keyword of JavaScript, and the file name should use XXX Svg or XXX-YYY Svg format

2.Be sure to pay attention to whether the input and output paths are correct

1.1.0

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago