ray-note/web/ESBuild 学习.md

16 lines
1.2 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

- 使用 `esbuild` 构建一个项目
- 使用命令构建
- 使用build脚本构建
- 使用 `build` 方法构建,不能使用 watch mode 和 serve mode
- 使用 `context` 方法进行构建,用来配合 `watch` , `serve``rebuild` 进行构建
- `watch` 在项目内容变更后,会自动进行编译
- `serve` 项目可以通过生成的 一个web服务进行访问每次刷新访问的时候会判断是否修改了内容如果内容发生变化则会重新编译一次项目
- `rebuild` 可以在创建出 `context` 之后,手动操作构建
- 停止 `context`上面的三种方法实现构建项目,构建过程不回主动停止,如果需要停止这个项目,可以中断命令的执行,或者调用 `context.dispose()` 会立即停止当前的 context
- `esbuild` 使用插件
- 官网有一个插件的实现案例用来获取系统的Path信息并进行显示 [参考地址]([esbuild - Plugins (docschina.org)](https://esbuild.docschina.org/plugins/))
- `onResolve` 钩子函数
用在路径解析过程中
`onResolve` 返回的 的内容中的 `namescape`, 后面 `onLoad` 会 根据这个`namespace` 进行过滤,并作出相应的数据
- `onLoad` 钩子函数
用在模块内容加载过程中时