-
Notifications
You must be signed in to change notification settings - Fork 578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor icons-svg@4.x with gulp & rename icons-svg-legacy #100
Conversation
由于 基本引入构建思路: import * as allIconDefs from '@ant-design/icons-svg';
const arr = Object.keys(allIconDefs).map(identifier => allIconDefs[identifier]);
Object.keys(allIconDefs).forEach(identifier => {
const iconDef = allIconDefs[identifier];
const { name, theme, icon } = iconDef;
// do something
}); |
@wendzhue 看看? |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Angular 的 js 文件没有像 React 和 Vue(或者说公用底包 /icons-svg
)那样拆成 AST 树,直接就是 SVG 字面量(用的时侯直接 innerHTML 即可),因为 Angular 没有原生 v-DOM 和渲染函数的支持。
不过好像我在 Angular 这边对打包脚本稍作修改就可以了,问题不大。
@wendzhue 我的本意是不希望再把整个构建过程像原来的icons-angular照搬一边+微修改的。利用提供的渲染函数写一个新的生成脚本替代原来的直接搬过来的替代过程如何? 思路类似这样 // generate.ts
// $ node generate.ts --require ts-node/register
import * as allIconDefs from '@ant-design/icons-svg';
import { renderIconDefinitionToSVGElement } from '@ant-design/icons-svg/es/helpers';
import { IconDefinition } from '@ant-design/icons-svg/es/types';
import * as path from 'path';
import { writeFile, emptyDir } from 'fs-extra';
export interface IconDefinitionNg extends Omit<IconDefinition, 'icon'> {
identifier: string;
icon: string;
}
export function walk<T>(fn: (iconDef: IconDefinitionNg) => Promise<T>) {
return Promise.all(
Object.keys(allIconDefs).map((identifier) => {
const iconDef = (allIconDefs as { [id: string]: IconDefinition })[
identifier
];
const { name, theme } = iconDef;
const inlineSvg = renderIconDefinitionToSVGElement(iconDef, {
// the options only affect the two-tone icons.
placeholders: { primaryColor: '#333', secondaryColor: '#E6E6E6' }
});
return fn({ name, theme, icon: inlineSvg, identifier });
})
);
}
(async () => {
await emptyDir(path.resolve(__dirname, `../lib/icons/defs`));
const publicApiRows = await walk(async ({ identifier, ...iconDef }) => {
await writeFile(
path.resolve(__dirname, `../lib/icons/defs/${identifier}.ts`),
`export const ${identifier} = ${JSON.stringify(iconDef)};`,
'utf8'
);
return `export { ${identifier} } from './defs/${identifier}';`;
});
await writeFile(
path.resolve(__dirname, `../lib/icons/public_api.ts`),
publicApiRows.join('\n'),
'utf8'
);
})(); |
该pr #91 由于冲突无法解决所以关闭
此 pr 包含以下可能具有破坏性的改动:
包相关变动
packages/icons
中的包名由@ant-design/icons-svg
修改为@ant-design/icons-svg-legacy
。包名@ant-design/icons-svg
由项目下的目录重写的packages/icons-svg
继承。新的
@ant-design/icons-svg
包和原来的版本 (4.0.0-alpha.0
和@ant-design/icons <= 2.1.1
) 相比,有如下改动:svg
目录dist.js
文件和压缩过的umd.js
文件,全量引入直接用import * as allIcons from '@ant-design/icons-svg'
, 走index.js
即可tree-shaking
的lib/index.es.js
文件manifest.js
文件es
目录用于tree-shaking
最终用户得到的目录如下:
这些改动的原则都是倾向于按需引入,保证主入口文件只有图标的导出,使得
import * as allIcons from '@ant-design/icons-svg'
只会导出图标信息。此PR来源于
#90
@ant-design/icon-kit
这个脚手架已自我废弃目前图标
查看当前全部图标
为什么
不使用
rxjs
响应式编程这类范式强大之处在于对可观察数据的时序性控制和数学上持续性赋值
:=
不同流的可组合性。图标生成就是文件系统IO和数据结构转换。显然gulp
及其生态能把这个任务做得更好,rxjs
也可以做但显然其长处并没有发挥出来,且编写无确切规范导致维护性差。速度与维护选择
WIP