【问题标题】:requiring angular with browserify需要带浏览器的角度
【发布时间】:2017-02-27 07:04:50
【问题描述】:

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

有什么问题??

【问题讨论】:

    标签: angularjs browserify


    【解决方案1】:

    我发现 browserify 不允许像这样的 require("./fi" + "le") 这样的“Concat in require”功能。但是另一个捆绑器(例如 webpack)允许该功能。

    【讨论】:

      猜你喜欢
      • 2014-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-07
      • 2019-11-09
      • 2016-04-07
      相关资源
      最近更新 更多