Skip to content

Instantly share code, notes, and snippets.

@poying
Created November 22, 2014 07:30
Show Gist options
  • Save poying/aaa143c60ca4ded224fd to your computer and use it in GitHub Desktop.
Save poying/aaa143c60ca4ded224fd to your computer and use it in GitHub Desktop.
var Duo = require('duo');
// 因為需要使用 app 上的屬性,
// 所以這邊把 middleware 包在一個 function 內,
// 這也是 Express、Koa 上標準的 Middleware 寫法。
module.exports = function (app) {
var isProduction = app.env === 'production';
return function *duoScript(next) {
if (this.path !== '/build/build.js') {
yield* next;
return;
}
var src = yield Duo(__dirname)
.entry('client/index.js')
// 透過 app.env 調開關選項
// development 開啟會有 source map
.development(!isProduction)
// cache 預設開啟,debug 時候會不方便,
// 在 development 的情況下我們將他關閉
.cache(isProduction)
.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