Salesforce Developers Blog: Modularizing Code in Lightning Components

Patterns For Sharing JavaScript Code Between Lightning Components

To move beyond basic Lightning Component development into composing larger and more complex Lightning Applications, you will need to learn how to share code and data across any number of components contained in an application.

Christophe Coenraets presents two options for creating modular, reusable code that can be shared across Lightning Components: Importing a JavaScript file into a Lightning Component using ltng:require, and using lightweight “service components” that perform specific utility functions and enable you to utilize multiple Apex controllers from within the containing component.

In this article you will learn how modularizing code eliminates duplication and enables reusability as you build larger and larger enterprise applications on the Lightning Platform.