Vendor dependencies bundled in Plugin SDK 2

0 favourites
  • 4 posts
From the Asset Store
Telegram Mini Apps SDK is a plugin that allows impliment Telegram Mini Apps features.
  • Hi.

    I'm developing a new Construct Plugin with SDK 2.

    For this particular plugin, I created a repository based on Vite.js as bundler to easily build a Construct Plugin using TypeScript and other useful stuff.

    (If it can be interesting, I will create a template repository on GitHub for other people to use as well.)

    ---

    Now... I'm facing this issue with vendor dependencies that I need to be bundled with the plugin itself.

    Note that these dependencies aren't added to the window object like old-usual global properties, but I'm using ES modules so they will be imported where they are needed.

    For this reason, I need a separated file, a new one, different from the usual files available for plugins.

    In my project, I make it so that it is compiled as a generic c3runtime/vendors.js file.

    BUT...

    This seems to be the actual problem.

    Plugins aren't meant to accept extra files, other than those defined.

    It doesn't seem to matter whether the file is mentioned inside the addon.json file or not...

    In my case:

    {
     /* ... */
    
     "file-list": [
     "c3runtime/plugin.js",
     "c3runtime/type.js",
     "c3runtime/instance.js",
     "c3runtime/conditions.js",
     "c3runtime/actions.js",
     "c3runtime/expressions.js",
     "c3runtime/vendors.js",
     "lang/en-US.json",
     "aces.json",
     "addon.json",
     "icon.svg",
     "index.js"
     ]
    }
    

    This leads to an eerror when running the project:

    [C3 runtime] Failed to load all engine scripts in worker: TypeError: Failed to fetch dynamically imported module: https://preview.construct.net/scripts/c3main.js
    

    Leaving aside the error message itself which, to be honest, doesn't say anything...

    To find out what the actual problem was, I had to to read the Network tab where I got a 404 over this file: https://preview.construct.net/scripts/plugins/Test_MyPlugin/c3runtime/vendors.js.

    How can I fix this?

    Can I hope for a fix for the Construct Plugin SDK (that would improve DX a lot) or do I need to do something different?

    Thanks.

  • See the section on using modules in the addon SDK documentation.

  • Oh, awesome!

    I lost the last commit from 3 weeks ago on https://github.com/Scirra/Construct-Addon-SDK/!

    That makes a lot more sense.

    Thanks!

    ---

    Just a personal thought, about this...

    Allowing developers to define their own c3runtime/main.js file is -indeed- a great thing.

    Just to try (let's not argue about if it was theoretically correct or not) I had Vite.js compile a single c3runtime/main.js file with all my plugin logic inside it.

    After all, my c3runtime/main.ts included all the different project files, so Vite.js did what it was asked to do: it included everything in a single file.

    This led me to have a single file inside my c3runtime directory.

    I edited -of course- both the addon.json and plugin.ts files accordingly, making sure it was the only runtime file listed inside the "file-list" array and configured it as the main script with the SetRuntimeModuleMainScript function.

    It just didn't work.

    It seems to still be looking for all the plugin-specific files (c3runtime/plugin.js, c3runtime/types.js, etc...), which leads to this error when the project is run.

    Now... I'm pretty sure I missed something, but...

    What's the point of allowing developers to define their own c3runtime/main.js if other different files are automatically searched anyway?

    ---

    But in the end, if you're also here looking for the solution, know that I didn't used this new c3runtime/main.js thing.

    What I was missing was simply this line inside my plugin.ts file:

    this._info.AddC3RuntimeScript("c3runtime/vendors.js");
    

    Add this and you'll be ok!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • What's the point of allowing developers to define their own c3runtime/main.js if other different files are automatically searched anyway?

    Construct only looks for files that your addon configures. But the default configuration includes runtime files plugin.js, type.js, instance.js etc. If you don't want the default configuration, call SetC3RuntimeScripts() with an array of just the script files you want to use.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)