Add factory code for RequireJS

cc: #266