Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugin support ESModule #22

Closed
wants to merge 2 commits into from
Closed

Conversation

Chinlinlee
Copy link
Member

Describe what this pull request is trying to achieve

Support plugin that uses ESModule

Additional notes and description of your changes

  • Add "scriptType":"module" in config(bluelight/data/plugin.json) when the plugin using ESMdoule
{
    "plugin": [
        {"path":"../scripts/plugin/esm-hello-world/index.js", "name": "esm-hello-world", "disableCatch": "true", "scriptType": "module"}
    ]
}
  • Default value is "text/javascript" when scriptType is not present in the config

Environment this was tested in

  • OS: Windows 10
  • Browser: Chrome 109.0.5414.120

test detail

  • Create hello world ESM
  • Folder structure
    image
  • esm-hello-world/hello-world-model.js
class HelloWorld {
    constructor() {}

    print() {
        console.log("hello world");
    }
}

export {
    HelloWorld
};
  • esm-hello-world/index.js
import { HelloWorld } from "./hello-world-model.js";

(() => {
    let helloWorld = new HelloWorld();
    helloWorld.print();
})();
  • bluelight/data/plugin.json
{
    "plugin": [
        {"path":"../scripts/plugin/oauth.js", "name": "oauth", "disableCatch": "true"},
        {"path":"../scripts/plugin/mpr.js", "name": "MPR", "disableCatch": "true"},
        {"path":"../scripts/plugin/vr.js", "name": "VR", "disableCatch": "true"},
        {"path":"../scripts/plugin/xml_format.js", "name": "xml_format", "disableCatch": "true"},
        {"path":"../scripts/plugin/graphic_annotation.js", "name": "graphic_annotation", "disableCatch": "true"},
        {"path":"../scripts/plugin/rtss.js", "name": "rtss", "disableCatch": "true"},
        {"path":"../scripts/plugin/seg.js", "name": "seg", "disableCatch": "true"},
        {"path":"../scripts/plugin/esm-hello-world/index.js", "name": "esm-hello-world", "disableCatch": "true", "scriptType": "module"}
    ]
}
  • Log screenshot
    image
  • Error occurs if missing "scriptType":"module" in config
{
    "plugin": [
        {"path":"../scripts/plugin/oauth.js", "name": "oauth", "disableCatch": "true"},
        {"path":"../scripts/plugin/mpr.js", "name": "MPR", "disableCatch": "true"},
        {"path":"../scripts/plugin/vr.js", "name": "VR", "disableCatch": "true"},
        {"path":"../scripts/plugin/xml_format.js", "name": "xml_format", "disableCatch": "true"},
        {"path":"../scripts/plugin/graphic_annotation.js", "name": "graphic_annotation", "disableCatch": "true"},
        {"path":"../scripts/plugin/rtss.js", "name": "rtss", "disableCatch": "true"},
        {"path":"../scripts/plugin/seg.js", "name": "seg", "disableCatch": "true"},
        {"path":"../scripts/plugin/esm-hello-world/index.js", "name": "esm-hello-world", "disableCatch": "true"}
    ]
}

image

@cylien cylien added the enhancement New feature or request label Feb 3, 2023
@cylien
Copy link
Member

cylien commented Mar 13, 2023

70db479
this work has been merged to PR 24

@cylien cylien closed this Mar 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants