web-ifc-three
web-ifc-three copied to clipboard
Support AMD Js
Does web-ifc-three
supports AMD using requirejs way of writing js? Do you have any example app in AMD?
This would be super useful to use IFC.js for viz inside Jupyter Notebooks!
At the moment, if I try to load for instance D3.js, the lib object is successfully printed to the console:
%%js
require.config({
paths: {
d3: "https://d3js.org/d3.v5.min"
}
});
require(["d3"], d3 => console.log(d3));
Whereas if I try the same with web-ifc-viewer:
%%js
require.config({
paths: {
webifcviewer: "https://cdn.jsdelivr.net/npm/[email protected]/dist/index"
}
});
require(["webifcviewer"], webifcviewer => console.log(webifcviewer));
An exception is thrown:
Uncaught SyntaxError: export declarations may only appear at top level of a module
well if you open https://cdn.jsdelivr.net/npm/[email protected]/dist/index.js you will see that it's this:
export * from './ifc-viewer-api';
export * from './base-types';
//# sourceMappingURL=index.js.map
so loading it in any way other than via import
will fail with that error
Indeed... do you know if it has any straightforward solution? or would the library need to be rewritten to work as an AMD?
you can try something like rollup dist/index.js --file dist/index.amd.js --format amd
locally maybe
Thanks, but unfortunately it doesn't work:
[!] RollupError: Could not resolve "./components" from "ifc-viewer-api.js"
Maybe it's not easy to do without rewriting the whole lib.
@cvillagrasa maybe cd dist
and run rollup from there?
I already did, the error is the same regardless of where it's run. Unfortunately, I think that every import would need to be changed to be relative to a baseUrl.