ti-commonjs icon indicating copy to clipboard operation
ti-commonjs copied to clipboard

Organization of app/lib files when adopting ti-commonjs

Open ghost opened this issue 9 years ago • 1 comments

http://docs.appcelerator.com/titanium/latest/#!/api/Global-method-require says:

Alloy For Alloy, place the CommonJS modules in the app/lib directory of your Alloy project, then load the module with the require method without the app/lib path and .js extension.

For example, a module file app/lib/myModule/module.js may be loaded by app/controllers/index.js using:

require('myModule/module');

What is the best way to organize things that were in app/lib when adopting ti-commonjs? There doesn't appear to be a way to add another search path, and ti-commonjs uses Resources whereas traditional Alloy appears to use both Resources and app/lib.

The options as I see them:

  • Use relative paths to reference things in app/lib from a controller
  • Move things that were in app/lib into Resources

Are there any other options? Any suggestions? Thanks!

ghost avatar Apr 03 '15 15:04 ghost

You pointed what in my humble opinion is the biggest issue with the current resolving algorithm.

Currently it resolves things as they are in the resulting app, that means that in a controller to reference a file in the lib directory you’ll need to do require('../../filename'). That’s because files in the lib dir will be placed inside the root of the Resources while controllers will be placed in Resources/alloy/controllers/*.

This is madness.

yuchi avatar Apr 06 '15 14:04 yuchi