web-ifc-three icon indicating copy to clipboard operation
web-ifc-three copied to clipboard

Support AMD Js

Open sonisourabh opened this issue 2 years ago • 7 comments

Does web-ifc-three supports AMD using requirejs way of writing js? Do you have any example app in AMD?

sonisourabh avatar Aug 08 '22 01:08 sonisourabh

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

cvillagrasa avatar Apr 25 '23 15:04 cvillagrasa

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

makc avatar Apr 26 '23 20:04 makc

Indeed... do you know if it has any straightforward solution? or would the library need to be rewritten to work as an AMD?

cvillagrasa avatar Apr 26 '23 20:04 cvillagrasa

you can try something like rollup dist/index.js --file dist/index.amd.js --format amd locally maybe

makc avatar Apr 26 '23 22:04 makc

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 avatar Apr 27 '23 16:04 cvillagrasa

@cvillagrasa maybe cd dist and run rollup from there?

makc avatar Apr 28 '23 19:04 makc

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.

cvillagrasa avatar Apr 29 '23 12:04 cvillagrasa