File tree Expand file tree Collapse file tree 5 files changed +52
-9
lines changed
en/guides/topic-detail/framework-plugin
zh/guides/topic-detail/framework-plugin Expand file tree Collapse file tree 5 files changed +52
-9
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @modern-js/app-tools ' : patch
3
+ ---
4
+
5
+ feat(app-tools): add isFirstCompile param to afterDev hook
6
+
7
+ feat(app-tools): 为 afterDev 钩子增加 isFirstCompile 参数
Original file line number Diff line number Diff line change @@ -260,9 +260,9 @@ export default (): CliPlugin => ({
260
260
# ## `afterDev`
261
261
262
262
- Function: Tasks to be executed after the main process of ` dev` command
263
- - Execution Stage: Executed after the project is started when running the ` dev` command
263
+ - Execution Stage: It is executed after each compilation is completed when running the ` dev` command
264
264
- Hook Model: AsyncWorkflow
265
- - Type: ` AsyncWorkflow< void , unknown> `
265
+ - Type: ` AsyncWorkflow< { isFirstCompile: boolean } , unknown> `
266
266
- Usage Example:
267
267
268
268
` ` ` ts
@@ -279,6 +279,24 @@ export default (): CliPlugin => ({
279
279
});
280
280
` ` `
281
281
282
+ ` afterDev` will be executed after each compilation is completed, you can use the ` isFirstCompile` param to determine whether it is the first compilation:
283
+
284
+ ` ` ` ts
285
+ import type { CliPlugin } from ' @modern-js/core' ;
286
+
287
+ export default (): CliPlugin => ({
288
+ setup(api) {
289
+ return {
290
+ afterDev: ({ isFirstCompile }) => {
291
+ if (isFirstCompile) {
292
+ // do something
293
+ }
294
+ },
295
+ };
296
+ },
297
+ });
298
+ ` ` `
299
+
282
300
# ## `beforeCreateCompiler`
283
301
284
302
- Function: Provides access to the Webpack configuration used to create the Webpack Compiler within middleware functions.
@@ -776,7 +794,7 @@ export default (): Plugin => ({
776
794
);
777
795
};
778
796
return next({
779
- App: hoistNonReactStatics(AppWrapper, App)
797
+ App: hoistNonReactStatics(AppWrapper, App),
780
798
});
781
799
},
782
800
};
Original file line number Diff line number Diff line change 2
2
title : Hook 列表
3
3
sidebar_position : 8
4
4
---
5
+
5
6
# Hook 列表
6
7
7
8
在 Modern.js 中暴露了三类插件:CLI、Runtime、Server。下面列举下各类中的 Hook:
@@ -166,7 +167,6 @@ export default (): CliPlugin => ({
166
167
});
167
168
` ` `
168
169
169
-
170
170
# ## `commands`
171
171
172
172
- 功能:为 command 添加新的命令
@@ -260,9 +260,9 @@ export default (): CliPlugin => ({
260
260
# ## `afterDev`
261
261
262
262
- 功能:运行 dev 主流程的之后的任务
263
- - 执行阶段:` dev` 命令运行时,项目启动完成之后执行
263
+ - 执行阶段:运行 ` dev` 命令时,每一次编译完成后执行
264
264
- Hook 模型:AsyncWorkflow
265
- - 类型:` AsyncWorkflow< void , unknown> `
265
+ - 类型:` AsyncWorkflow< { isFirstCompile: boolean } , unknown> `
266
266
- 使用示例:
267
267
268
268
` ` ` ts
@@ -279,6 +279,24 @@ export default (): CliPlugin => ({
279
279
});
280
280
` ` `
281
281
282
+ ` afterDev` 会在每一次编译完成后执行,你可以通过 ` isFirstCompile` 参数来判断是否为首次编译:
283
+
284
+ ` ` ` ts
285
+ import type { CliPlugin } from ' @modern-js/core' ;
286
+
287
+ export default (): CliPlugin => ({
288
+ setup(api) {
289
+ return {
290
+ afterDev: ({ isFirstCompile }) => {
291
+ if (isFirstCompile) {
292
+ // do something
293
+ }
294
+ },
295
+ };
296
+ },
297
+ });
298
+ ` ` `
299
+
282
300
# ## `beforeCreateCompiler`
283
301
284
302
- 功能:在中间件函数中可以拿到创建 Webpack Compiler 的 Webpack 配置
@@ -778,7 +796,7 @@ export default (): Plugin => ({
778
796
);
779
797
};
780
798
return next({
781
- App: hoistNonReactStatics(AppWrapper, App)
799
+ App: hoistNonReactStatics(AppWrapper, App),
782
800
});
783
801
},
784
802
};
Original file line number Diff line number Diff line change @@ -179,7 +179,7 @@ export default ({
179
179
async onDevCompileDone ( { isFirstCompile } ) {
180
180
const hookRunners = api . useHookRunners ( ) ;
181
181
if ( process . stdout . isTTY || isFirstCompile ) {
182
- hookRunners . afterDev ( ) ;
182
+ hookRunners . afterDev ( { isFirstCompile } ) ;
183
183
184
184
if ( isFirstCompile ) {
185
185
printInstructions ( hookRunners , appContext , normalizedConfig ) ;
Original file line number Diff line number Diff line change @@ -76,7 +76,7 @@ export type AppToolsHooks<B extends Bundler = 'webpack'> = {
76
76
77
77
// beforeCreateBuilder
78
78
beforeDev : AsyncWorkflow < void , unknown > ;
79
- afterDev : AsyncWorkflow < void , unknown > ;
79
+ afterDev : AsyncWorkflow < { isFirstCompile : boolean } , unknown > ;
80
80
beforeCreateCompiler : AsyncWorkflow <
81
81
{
82
82
bundlerConfigs ?: B extends 'rspack'
You can’t perform that action at this time.
0 commit comments