使用browserify需要角度

时间:2017-02-27 07:04:50

标签: angularjs browserify

我对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);
    }
  }

有什么问题?

1 个答案:

答案 0 :(得分:0)

我发现浏览器不允许“需要时使用Concat”功能,例如require(“./ fi”+“le”)这样的事实。但另一个捆绑商如webpack允许这个功能。

相关问题