![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@all-in-js/svg-icons
Advanced tools
一个基于 svg 的图标管理和组件化方案
整体工作流程分为两步:
npm i pineapple@latest
支持设置渐变、多色、兼容本地 svg 组件等特性,支持通过配置 webpack loader 自动同步管理平台上的图标数据集,也可以加载本地的图标数据集;
import Vue from 'vue';
import SvgIcon from 'pineapple';
Vue.use(SvgIcon, {
tagName: 'xxx-icon'
});
<template>
<xxx-icon
name="icon"
color="red green">
</xxx-icon>
</template>
名称 | 类型 | 默认值 | 说明 |
---|---|---|---|
svgIcons | object | - | svg数据集 |
tagName | string | svg-icon | 组件名 |
isStroke | boolean | false | 默认使用描边样式 |
defaultWidth | string | - | 默认宽 |
defaultHeight | string | - | 默认高 |
名称 | 类型 | 默认值 | 说明 |
---|---|---|---|
rotate | number | false | 旋转角度 |
spin | boolean | false | 是否添加旋转动画,实现loading效果 |
icon | string | - | 图标名称 |
name | string | - | 图标名称 |
width | string | - | 图标宽 |
height | string | - | 图标高 |
scale | number | - | 放大倍数 |
fill | boolean | true | 使用填充样式 |
color | string | - | 颜色 |
title | string | - | 标题 |
original | boolean | - | 是否使用图标的原色 |
并修改 webpack 配置,参考:
复杂粘贴即可,只需修改 projects
rules: [
{
test: /\.js$/,
loader: 'pineapple/babel-sync-svg-icons-loader',
options: {
requestUri: 'http://locale.server',
projects: 'demo'
}
}
]
相关配置参数:
名称 | 类型 | 默认值 | 说明 |
---|---|---|---|
requestUri | string | - | 拉取图标数据集的接口 |
projects | string | common | 项目 alias,多个用逗号隔开 |
cacheResponse | boolean | true | 是否缓存已拉取过来的图标数据集,为 true 时,当图标有更新后,需要重启应用 |
支持使用包自带的 svg2js 命令将本地的 svg 文件转换成组件可用的数据集;
svg2js assets/svgs --outFile svgs.js
支持使用包自带的 pull-svg 命令拉取管理平台上的图标数据;
pull-svg --projects demo --outFile svgs.js
import Vue from 'vue';
import SvgIcon from 'pineapple';
import SvgIcons from 'assets/js/svgs.js';
Vue.use(SvgIcon, {
tagName: 'xxx-icon',
svgIcons: SvgIcons
});
优化 svg 信息,删除多余节点,压缩 svg 体积,并将节点信息转为 js,方便统一管理和进一步的优化工作;
const { SvgOptimize } = require('pineapple/scripts/svgo');
const svgo = new SvgOptimize({/* svgo options */});
(async () => {
/**
* svgInfo: {
* name: string;
* data: string;
* viewBox: string;
* width: number;
* height: number;
* }
*/
const svgInfo = await svgo.build('svg-filename', 'svg-content');
})();
FAQs
> 一个基于 svg 的图标管理和组件化方案
The npm package @all-in-js/svg-icons receives a total of 2 weekly downloads. As such, @all-in-js/svg-icons popularity was classified as not popular.
We found that @all-in-js/svg-icons demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.