kvindascr / angular-enterprise-kickstart

Angular Enterprise Kickstart - Kickstart your enterprise project. Based from ng-boilerplate
http://www.alivebox.com/projects/aeks
Other
29 stars 5 forks source link

Require paths in common directory #2

Closed shawnmann closed 10 years ago

shawnmann commented 10 years ago

I want to add a "security" module to the common folder, but in my security module's index.js I need to "define" the module's script files with "full" paths from the app folder to get it to work. Is this broken, or have I configured something incorrectly? If I want the modules in common to be completely stand alone, I can't assume that the module exists in a "common" folder, etc. Any help would be awesome!

kvindascr commented 10 years ago

Hello Shawnmann, Two comments. Usually it is required to point the full path to the index.js, but after that, index.js will load the internal files relatively lets say. Also do not completely understand your idea of the standalone module, can you elaborate on it to be able to help? We can also take a look at your code to give you some hints.

Let me know your thoughts.

shawnmann commented 10 years ago

Two things:

Purpose of Common Folder and Stand Alone Modules

The common folder is for stand alone modules right? As in, modules I could drop into another project and use - they don't rely on anything but what is included in their module folder (except for depending on Angular/Require).

Perhaps I have misunderstood the intent of the common folder. I thought it was for highly reusable and compartmentalized modules, such as a security module, or an error handling module.

Require in Common folder vs App folder

Here is my specific issue:

In an app module's index.js, located in "app/modulename", you can configure your define statement as follows:

define([
    './partials/partials',
    './controllers/index'
], function () {});

These paths are based out of the module folder, not the app folder. This works fine for me. My issue is when I try to do the same thing inside the common folder. Attempting to use a path "based" in the module folder will not work for me. I have to do the following instead, in my module's index.js:

define([
    '../common/vba-security/services/index',
    '../common/vba-security/module'
], function () {});

But this means that my module is now reliant on a particular app structure. I expected it to work like the modules in the app folder.

So I am not sure if I configured something incorrectly, or if this is expected.

kvindascr commented 10 years ago

Hello Shawnmann,

Let me try to replicate the scenario later today and get back to you.

I think I now have a clear picture.

kvindascr commented 10 years ago

Hello Shawnmann,

I just replicate the scenario but I think the current structure won't provide you with what you're looking for.

Let me first explain the issue, and later on explain the alternatives you can follow.

The issue is generated because the root path for RequireJS is the app folder. As common is outside the app folder, RequireJS tries to resolve the relative paths inside the app folder.

We were using the common folder to put libraries already compiled lets say, and not using RequireJS as part of their development, in our case in specific, because the libraries may be reused in some projects not based in RequireJS.

In any case here I provide you some alternatives you can follow.

  1. Move the security module inside the app folder. You can create a commons submodule inside the app folder.
  2. Make the commons/vba-security an isolated module on its own, maybe even with its own build system, that generates a final compiled js file which you require via the requirejs config.

With 1 or 2 you can also use git submodules to handle the module as a complete separate project.

Now due to this issue lets say the principle of complete reusable modules is not being fulfilled 100% percent, at least when using RequireJS in the common module.

We are planning some things to improve on the project, on build at the moment, but we will also consider this to improve the structure.

Let me know if you find this comment helpful.

shawnmann commented 10 years ago

Ok, this makes sense. Perhaps I should just add a common folder inside the app - that is probably easiest. I want a place to put my "stand alone" app modules, and that will suffice. Thanks for the explanation!

Shawn