# 編寫插件
如果你打算自己寫一個 Gulp 插件,為了節約你的時間,你可以先完整地閱讀下這個文檔。
* [導覽](guidelines/) (必讀)
* [使用 buffer](using-buffers/)
* [使用 stream 來處理](dealing-with-streams/)
* [測試](testing/)
## 它要做什么?
###?流式處理文件對象(Streaming file objects)
gulp 插件總是返回一個 [object mode](http://nodejs.org/api/stream.html#stream_object_mode) 形式的 stream 來做這些事情:
1. 接收 [vinyl File 對象](http://github.com/wearefractal/vinyl)
2. 輸出 [vinyl File 對象](http://github.com/wearefractal/vinyl)
這通常被叫做 [transform streams](http://nodejs.org/api/stream.html#stream_class_stream_transform_1) (有時候也叫做 through streams)。transform streams 是可讀又可寫的,它會對傳給它的對象做一些轉換的操作。
### 修改文內容
Vinyl 文件可以通過三種不同形式來訪問文件內容:
* [Streams](dealing-with-streams/)
* [Buffers](using-buffers/)
* 空 (null) - 對于刪除, 清理, 等操作來說,會很有用,因為這時候內容是不需要處理的。
## 有用的資源
* [File object](https://github.com/wearefractal/gulp-util/#new-fileobj)
* [PluginError](https://github.com/gulpjs/gulp-util#new-pluginerrorpluginname-message-options)
* [event-stream](https://github.com/dominictarr/event-stream)
* [BufferStream](https://github.com/nfroidure/BufferStream)
* [gulp-util](https://github.com/wearefractal/gulp-util)
## 插件范例
* [sindresorhus' gulp plugins](https://github.com/search?q=%40sindresorhus+gulp-)
* [Fractal's gulp plugins](https://github.com/search?q=%40wearefractal+gulp-)
* [gulp-replace](https://github.com/lazd/gulp-replace)
## 關于 stream
如果你不熟悉 stream,你可以閱讀這些來
* https://github.com/substack/stream-handbook (必讀)
* http://nodejs.org/api/stream.html
其他的一些為 gulp 創建的和使用的,但又并非通過 stream 去處理的庫,在 npm 上都會被打上 [gulpfriendly](https://npmjs.org/browse/keyword/gulpfriendly) 標簽。
- gulp 中文文檔
- 入門指南
- gulp API 文檔
- 編寫插件
- 指導
- 使用 buffer
- 使用 Stream 處理
- 測試
- FAQ
- gulp 技巧集
- 整合 streams 來處理錯誤
- 刪除文件和文件夾
- 使用 watchify 加速 browserify 編譯
- 增量編譯打包,包括處理整所涉及的所有文件
- 將 buffer 變為 stream (內存中的內容)
- 在 gulp 中運行 Mocha 測試
- 僅僅傳遞更改過的文件
- 從命令行傳遞參數
- 只重新編譯被更改過的文件
- 每個文件夾生成單獨一個文件
- 串行方式運行任務,亦即,任務依賴
- 擁有實時重載(live-reloading)和 CSS 注入的服務器
- 通過 stream 工廠來共享 stream
- 指定一個新的 cwd (當前工作目錄)
- 分離任務到多個文件中
- 使用外部配置文件
- 在一個任務中使用多個文件來源
- Browserify + Uglify2 和 sourcemaps
- Browserify + Globs
- 同時輸出一個壓縮過和一個未壓縮版本的文件
- 改變版本號以及創建一個 git tag
- Swig 以及 YAML front-matter 模板