Web Builder 技术方案 #15
Unanswered
anncwb
asked this question in
Solutions Discussions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
描述
Web Builder 是一个由 Growing Web 提出的项目构建技术标准,它不受其它构建工具制约,不限制于
vite
、webpack
等其它第三方构建工具,旨在抹平不同工具的差异性,由 Web Builder 内部择优选择不同的构建工具,通过读取解析工程清单project-manifest.json
内所约束的标准应用格式配置,开发者只需要配置清单即可完成项目的开发、构建、发布。它支持多种构建(esm
、cjs
、system
、·iife
)格式的输出,也支持库模式(lib
)、网站模式(app
)两种目标的构建。工具构建流程
Web Builder 将提供
CLI
和Node.js
API 两种使用方式,以下为构建工具整体流程动机
统一的构建工具与模板代码能缓解项目之间各自为政的问题,但随着时间的推移,构建配置与模板代码将会被项目同化。当企业项目数量变多或规模变大的时候,原来运作良好的部分都会变得糟糕,而工程的复杂度却阻碍了基础设施的升级,这样的问题在不同的企业、不同的团队反复发生,因此我们希望将最基础的部分从业务工程中抽离出来,建设成高可用的解决方案,借机建立必要的约束以维持长久的稳定。
基本示例
前置配置
运行
直接运行
npm run dev
即可运行项目,无需配置相关参数,工具会自动择优选择vite
、webpack
其中的一个进行启动(目前只支持 vite),并根据项目类型(支持vue2
、vue3
、react
、lit
、preact
、vanilla
)进行启动详细设计
CLI 命令设计
CLI 命令包含
dev
、build
两个命令,其余命令暂不支持,可做后续扩展,这里暂不讨论dev
基本命令为:
web-builder dev
命令行参数:
--mode
指定环境模式--open
在服务器启动时打开浏览器--https
指定是否启用 https--mkcert
在服务器启动时创建证书证书build
基本命令为:
web-builder build
命令行参数:
--mode
指定环境模式--no-clean
在构建项目之前不要删除 dist 目录--report
生成 report.html 以帮助分析捆绑内容--report-json
生成 report.json 以帮助分析捆绑内容--sourcemap
构建项目后生成map
文件--watch
实时监听变化并构建清单加载
工程清单加载见:工程清单技术标准
配置文件加载
配置文件与工程清单的区别在于,工程清单 用于指定工程构建必须的配置,配置清单用于配置开发体验、非必需配置相关的内容以及插件引入。
配置文件支持以下4种格式:
web-builder.config.ts
web-builder.config.mjs
Alias 内置
默认内置了
~
别名,其余 Alias 配置暂不允许配置,防止过多的别名带来了更多的认知成本Bundler 模块
Bundler 模块用于提供多种构建器,方便进行切换,每个构建器为一个
npm
子包,通过所设置的bundlerType
加载器类型,由lodaer
加载器进行加载:插件模块
WIP
待讨论的问题
参考
Beta Was this translation helpful? Give feedback.
All reactions