screetbloom / blog Goto Github PK
View Code? Open in Web Editor NEW🎸 My Blog
🎸 My Blog
先收敛,二次修改一下再发出
我本人是 Vue CLI 生态技术的爱好者,期望可以基于 Vue CLI 进行企业内的跨 Vue/React 技术栈的二次定制
目前的 Vue CLI 的插件发现策略是 /^(@vue\/|vue-|@[\w-]+(\.)?[\w-]+\/vue-)cli-plugin-/
但是在公司内,是有一些诉求的:
@fe/react-cli-plugin-x
@fe/xxx-cli-plugin-x
这个时候直接使用 Vue CLI 就没法满足需求,需要进行侵入式的改造,Fork 是我不愿意采取的形式
在企业内,我们开发一些插件是希望能够具体统计出这个插件服务的范围和使用次数的;比如一个编译提速的插件,需要了解到这个插件的使用范围和次数才能衡量出工具对业务的帮助,比如号称 xxx 工具可以提效人力 20%,但是没有数据是没人认可的
这个需求是需要对插件机制的加载执行进行打点统计的,一般情况下也需要进行侵入式的代码改造
企业内忌讳重复建设,需要保证大家不会疯狂重复造类似轮子,而是类似能力的轮子可以以共建的方式持续迭代和维护,质量和人力节省上都能有提升
我们采取的策略是进行插件分析,通过大概的 Api + 名称 去判断是否重复
比如目前 Vue CLI 仅在 create 阶段有 preset 能力,而企业内会希望在 service 阶段也能有 preset 能力
- 收敛 package.json 中的插件数量、对一线同学屏蔽过多插件带来的理解复杂度
- 企业内使用 Vue CLI 的部分项目 dependencies + devDependencies 数量可以达到 50+,preset 之后可以把 12+ 插件全部收敛,降低理解成本
- 对比 Umi 也有 preset 能力,只不过叫「垂直场景解决方案」或者「场景套件」
其它的定制能力:
比如
yarn serve/dev
后进行用户 inquirer
交互式对话And 其它一些诉求
核心想法是希望能够在按需拓展能力的前提下,同时兼容 Vue CLI 已经沉淀的生态能力
插件运行机制
:重写了 Vue CLI 的插件发现、注册、加载、执行,兼容原始 Vue CLI 插件的加载和执行API
:Vue CLI API(PluginAPI、GeneratorAPI)等暴露的是一个个 class,直接 extends
然后按需覆盖、增加内置插件
:Vue CLI 的插件基本都是一个个的 js 文件,以形如 require('vue-cli-service4/lib/config/app')
的方式获取此文件,然后直接执行即可,这部分增强的诉求不大因为「运行机制」是完全重写的,因此可以支持自定义插件命名的发现策略、增加使用打点、插件分析等能力
想了解一下是否有更优雅的解法
如果 Vue CLI 可以抽象一波,类似 @umijs/core 可能会比较棒
如何定制企业级前端研发框架
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.