Using javascript modules in suitecrm

Hi all, I’m curious if anyone here has experience or insights into using ES6 JavaScript modules in SuiteCRM. Specifically, I’m looking for advice on how to best structure and include modular JavaScript code in custom views without running into issues with script loading order or scope.

For context, here’s a simple example of what I’m trying to achieve:


// custom/js/baseClass.js
export class baseClass {
    // baseClass logic
}

// custom/js/derivedClass.js
import {baseClass} from './baseClass.js';
export class derivedClass extends baseClass{
    // derivedClass Logic
}


// In my custom view I would like to use the derived class

class customViewEdit extends ViewEdit {
    function display() {

        $base_path = 'custom/js/derivedClass.js';
        $record_id = $this->bean->id;

        echo <<<EOT
         <script src="$base_path"></script>
        <script>
                new derivedClass('$record_id')
        </script>
        EOT;

        parent::display();
    }
}