We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Service 确定如何实现诸如 start、build 的命令,可以是由函数或类实现,比如(以 webpack 为例):
start
build
import { Service } from 'build-scripts'; import start from './start'; import build from './build'; import WebpackChain from 'webpack-chain'; import webpack from 'webpack'; const webpackService = new Service<WebpackChain, Record<'webpack', typeof webpack>>({ name: 'webpack', command: { start, build }, bundlers: { wepback } }) export default webpackService; // start.ts 实现 npm run start // build.ts 实现 npm run build // 参考实现如下 export default start = (context: Context<WebpackChain>) => { const { getConfig, applyHook } = context; const configArr = context.getConfig(); await applyHook(`before.${command}.load`, { xxx }) try { compiler = webpackInstance(webpackConfig); } catch (e) { await applyHook('error', { err }); } compiler.run((err, stats) => { // }) await applyHook(`after.${command}.compile`, result) }
Service API
Service 可消费 Context 的所有 public API:
interface Context { command: 'build' | 'start' | 'test', commandArgs: object; rootDir: string; pkg: Json; applyHook: (key: string, opts?: {}) => Promise<void>; logger: Logger; ... }
插件 API 与现有插件 api 基本保持一致(除部分存在命名上变更)。主要变更有:
onGetWebpackConfig
onGetConfig
// 入参 config 与 registerTask 配置 对应 interface onGetConfig<T> { (name: string, fn: (config: T)): void; (fn: (config: T)): void; }
registerTask
ctx
webpack
之前存在从 ctx 下导出 wepback 的场景,目的是保证使用的是统一 webpack 实例。新模式下,需要 Service 注入给 Plugin 消费。
const ctx = createContext({ command: 'start', rootDir: this.options.rootDir, bundlers: { webpack } })
configWebpack
setConfig
Task 通过插件注册,注册方式如下:
const plugin = ({ registerTask }) => { // 以 webpack 为例,注册 webpack-chain 配置 registerTask('taskName', webpackConfig); }
Context API 变更
registerCommandModules
getCommandModule
getWebpackConfig
getProjectFile
依赖包升级
Service 可消费的 api
The text was updated successfully, but these errors were encountered:
建议补充下 现有 webpack 体系在新架构下涉及到哪些 API 需要定制,已经定制逻辑中的伪代码
Sorry, something went wrong.
对于 getConfig,最好增加标识看下当前是 webpack 还是 rollup,避免webpack4 => 5的恶心的兼容
指的是在配置层面能够感知 具体是 webpack 还是 rollup? getConfig 上的 config 具体包含哪些配置主要由上层工具决定,比如 ice/pkg 和 icejs
No branches or pull requests
背景
方案
build-scripts 分层设计
Service 规范
Service 确定如何实现诸如
start
、build
的命令,可以是由函数或类实现,比如(以 webpack 为例):Service API
Service 可消费 Context 的所有 public API:
插件 API
插件 API 与现有插件 api 基本保持一致(除部分存在命名上变更)。主要变更有:
onGetWebpackConfig
→ 变更为onGetConfig
,使用方式保持与之前不变registerTask
入参变更ctx
不再默认导出webpack
之前存在从 ctx 下导出 wepback 的场景,目的是保证使用的是统一 webpack 实例。新模式下,需要 Service 注入给 Plugin 消费。
configWebpack
字段修改为setConfig
,入参为 Task Config。注册 Task
Task 通过插件注册,注册方式如下:
具体改动
Context API 变更
registerCommandModules
getCommandModule
getWebpackConfig
getProjectFile
- 移进 utils 文件夹,修改名为 loadPkg依赖包升级
Service 可消费的 api
The text was updated successfully, but these errors were encountered: