Smile CDR v2024.08.PRE
On this page:

40.3.1ECMA Modules


Enabling ECMA Module mode provides a way to break up your JavaScript code into multiple files. This is useful for organizing your code and for reusing code across multiple scripts. ECMA Module Mode

ECMA Module mode is enabled by setting the javascript.ecma_module_mode property to true in the module where the script is being used. Modules

To import a module, use the import statement. For example:

import {Foo} from 'scripts/my_module.mjs';

export function handle() {
   const foo = new Foo();
   return foo.square(42);

where my_module.mjs is a file in a subdirectory of the smilecdr root directory called "scripts". In this example my_module.mjs could contain something like the following:

export class Foo {
   square(x) {
      return x * x;
When running in ECMA Module mode, any function you want to be visible to Smile CDR must be exported.