2017-02-27 25 views
0

私はangularjsでかなり新しいです。私はbrowserifyでアプリケーションを開発しています。ブラウザで角度を指定する必要があります

文字列にrequireを使用すると機能します。しかし、それを組み合わせた文字列で使うと、うまくいきません。

require('./todo')は働いていますが、var todo = 'todo'; require('./' + todo)はありません。

問題コードindex.jsはこちらです。

var fs = require('fs'); 

    var files = fs.readdirSync(__dirname); 
    var controllers = module.exports = {}; 

    // files.length is 2 and the names are index.js and todo.js 
    for (var i=0; i<files.length; i++) { 
    var file = files[i]; 
    if (file !== 'index.js') { 
     var fileName = file.split('.')[0]; 
     var modulePath = './' + fileName; 

     // below code is working. 
     controllers[fileName] = require('./todo'); 

     // below code is not working. The error code -> Uncaught Error: Cannot find module './todo' 
     controllers[fileName] = require(modulePath); 
    } 
    } 

何が問題ですか?

答えて

0

私はbrowserifyがrequire( "./ fi" + "le")のような 'Concat in require'機能をこのように許可していないということを知りました。しかし、webpackのような別のバンドラがこの機能を許可しています。

関連する問題