javascript - How does requiring modules manually differ from calling them dynamically with browserify? -
Sorry for the strange post title, but it's a very strange situation inside. In my project I have such folder structure:
/ filter index.js [...] / controller index.js [...] app.js
App JS
is basically the entry point of my application and I think it would be nice if I can automatically load the contents of those directories with the requirement of I am
Directory and index .js
take care of loading in all the directories that need to load it.
But I'm running into a problem that I do not understand. Because I'm deliberately frustrated (this is a learning / experiment practice) I tried and decided to keep it dry as human, so I tried this big code to handle module loading:
< Pre> 'strict use'; Var custom modules = ['controller', 'filter']; //require('/controllers'); //require('./filters'); (For var i in custom module) {if (custom module hasOwnProperty (i)) {Required ('./' + custom module [i]); }} Var Basic Module = ['NGSNetis']; Angular Module ('app', custom modules.cocket (original module));
I plan to remove it from my module but will do it for display. For some reasons, this code throws this exception:
Unwanted error: Module './controllers' can not be found
But when I call it a Static string
is required ('./controller');
No problem, everything works and my sample application behaves as expected. Check out
(emphasis my):
Browser entry entry The point starts on files that you give it and searches for any requirement () call it the static analysis source syntax tree. Calling
each with a string in it , the browser resolves those module strings to file those paths, and then those files Paths are required to search () calls again until recursively the entire dependency graph is visited.
Bottom line: Dependency must be declared static; The dynamically generated requirement ()
is the code containing the call (there is a good idea in theory).
You can get the same results using server-side or build-time technology.
Comments
Post a Comment