JS Modules

Filename jsmodules.yml
Root Node none


type: map

Webpack entry points configuration. For each new entry point, add the script tag with the entry point file path to the twig template or layout update to load the entry point file on a page.

        - oroui/js/app
        - oroui/js/app/services/app-ready-load-modules


type: map

This section is used when a desired module name does not match the path to the module. The keys of the map are module names with trailing $ which are mapped to the actual path of the file that contains the module’s source code. Webpack provides the corresponding syntax and description in its documentation (see Webpack Resolve Alias). Aliases can help import certain modules easily using short names.

    backbone$: backbone/backbone
    oro/block-widget$: oroui/js/widget/block-widget


type: sequence

Introduces a list of modules that should be initialized before application is launched. They can be used to track certain page events with bundle specific handlers, etc.

    - oroui/js/app/modules/jstree-actions-module
    - oroui/js/app/modules/layout-module


type: map

Each module that should be configured at runtime (e.g., via twig templates) must be specified in this section where the key of the map is a module name, and the value is an empty object.

    controllers/page-controller: {}
    oroui/js/app: {}


type: map

Add a module name to this section to be able to import a module with the name that is determined at runtime.

import loadModules from 'oroui/js/app/services/load-modules';

loadModules(moduleName).then(module => module.init());

Insert a module name to this section nested into the subsection with the name of webpack build chunk where modules have to be added.

        - jquery
        - oroui/js/app/components/view-component


A chunk name should either be a new name or already exist in another bundle. It is preferred to group modules that are used together or/and on specific pages for the maximum benefit of the webpack chunk concept.


type: map

The map option allows to substitute a module with the given ID with a different module. Such substitution is working for the given module prefix.

For example, OroUIBundle is delivered with an extended version of the jQuery library. This means that all modules should receive the extended jQuery library from the OroUIBundle. However, since the bundle itself needs the original version of the library to be able to extend it, it must get the original version when requiring it:

        'jquery': 'oroui/js/jquery-extend'
        'jquery': 'jquery'


* is a special key that matches all module contexts.


type: map

Webpack places each module in its local scope, however, some third party libraries may expect global dependencies (e.g., $ for jQuery). The libraries may also create globals which need to be exported, so they can stop working. To solve this issue, webpack offers a shimming feature. See Webpack Shimming In our shim section, each key of the map is the name of a module to be created. For each module, a map that configures the module must be specified. It can consist of the following keys:

imports (type: sequence)

If the library depends on specific global variables, these dependencies can be listed here. See Webpack Imports Loader for the detail.

exports (type: string)

The name of a JavaScript symbol that is exposed to other parts of the system that use this symbol. See Webpack Exports Loader for the details.

expose (type: sequence)

Specify which local variables have to be exposed globally. See Webpack Expose Loader for the details.
            - jQuery=jquery
            - $
            - jQuery
        exports: Select2
            - jQuery=jquery
        expose: loadModules