Load Javascript File as ECMA 6 Module
Added by lm at almost 2 years ago
How should we load "Module" JS files? A few years ago, I had modified WApplication::require
to take a std::string const & type = std::string ()
that, when "module"
was passed, that type of javascript file could be loaded. Is this possible with Wt?
Replies (3)
RE: Load Javascript File as ECMA 6 Module - Added by lm at almost 2 years ago
I created a change that allows loading ECMA 6 Module Javascript files: https://github.com/limitedAtonement/wt/commit/2f9327059c7ef9fcbea9adf678ce654c1346c079
You can see that it works here: https://brightlight.today/speedlines/
https://brightlight.today/speedlines/js/gameplay.js is loaded using Wt::WApplication::require("js/gameplay.js", "module, "");
.
RE: Load Javascript File as ECMA 6 Module - Added by Roel Standaert almost 2 years ago
There's no feature like that in Wt yet, apart from putting the script tag in <head-matter>
in your wt_config.xml
.
That patch breaks backwards compatibility (adding an extra std::string
argument between two existing string arguments), so we can't add support for it like that.
We may consider turning WApplication::ScriptLibrary
into a public class to facilitate this, similar to how we aim to address adding the SameSite
attribute to cookies in issue #7814.
RE: Load Javascript File as ECMA 6 Module - Added by Stefan Bn about 1 year ago
I stumpled across this situation in my project as well. I've created a feature request for this: