You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
According to the Qt docs at https://doc.qt.io/qt-5/qtqml-javascript-imports.html, Qt supports importing .js and .mjs Javascript files. In the Qt world, .mjs files are basically the same as .js, but they can import/export modules, which .js files can't. I maintain an extension that is almost 2,000 lines and looking to break things down in several files/modules. The only way (other than using a JS bundler) is to save the modules in .mjs files. Unfortunately it seems like Tiled only looks for .js files and not .mjs files in the extension folder. I think this would be an easy change and would allow publishing modular extensions without messing with antiquated bundlers. Thank you for considering it!
The text was updated successfully, but these errors were encountered:
I had tried loading modules as well in the past, and I hadn't gotten it to work. But now carefully reading this documentation again, I noticed that it says that importing modules only works from .mjs files. And since I was evaluating JavaScript using QJSEngine::evaluate, Qt would never have been aware that the script came from a module.
So, I've made a patch that uses the QJSEngine::importModule function, added in Qt 5.12, when encountering .mjs files. And indeed loading modules from there appears to work!
So, starting with Tiled 1.8, it will be possible to write and distribute extensions as .mjs files, and then you can also use the import and export mechanism to write modular code. :-)
According to the Qt docs at https://doc.qt.io/qt-5/qtqml-javascript-imports.html, Qt supports importing .js and .mjs Javascript files. In the Qt world, .mjs files are basically the same as .js, but they can import/export modules, which .js files can't. I maintain an extension that is almost 2,000 lines and looking to break things down in several files/modules. The only way (other than using a JS bundler) is to save the modules in .mjs files. Unfortunately it seems like Tiled only looks for .js files and not .mjs files in the extension folder. I think this would be an easy change and would allow publishing modular extensions without messing with antiquated bundlers. Thank you for considering it!
The text was updated successfully, but these errors were encountered: