Created
November 22, 2014 07:19
-
-
Save poying/77ccb72d50d025143c9b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Duo = require('duo'); | |
// 以 js 為例,css 作法相同 | |
function *duoScript(next) { | |
// 如果有使用 koa-router 之類的 module 就不需要自行判斷 path | |
// 目前先以最單純的 koa 為例 | |
if (this.path !== '/build/build.js') { | |
// yield* 後面直接接 generator function | |
yield* next; | |
return; | |
} | |
// 不用懷疑,直接把那個 class 當 function call 就對了, | |
// 在 Component.io/Duo 的 Component 內也都有相同習慣, | |
// 當然用 new 也是可以的。 | |
// | |
// root 我習慣設成專案根目錄,這邊假設 __dirname 已經是根目錄了 | |
var src = yield Duo(__dirname) | |
// 相對路徑 | |
.entry('client/index.js') | |
// 用一些 plugin,像是 duo-regenerator | |
// 自己習慣在前端也使用 co,所以這個我必用 | |
.use(regenerator()) | |
// 執行 | |
.run(); | |
this.type = 'application/javascript'; | |
this.body = src; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment