Skip to content

Commit 2bc3739

Browse files
committed
updated npm package nexus3d to modern standards
1 parent 3f5178a commit 2bc3739

3 files changed

Lines changed: 52 additions & 38 deletions

File tree

nexus3d/package.json

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,16 @@
3232
"dependencies": {
3333
"three": "^0.181.0"
3434
},
35-
"files": [
36-
"build/nexus3D.min.js",
37-
"build/nexus3D.js",
38-
"dist/corto.em.js",
39-
"LICENSE",
40-
"package.json",
41-
"README.md",
42-
"src"
43-
]
35+
"files": [
36+
"build/nexus3D.js",
37+
"build/nexus3D.min.js",
38+
"build/corto.worker.js"
39+
],
40+
"exports": {
41+
".": {
42+
"import": "./build/nexus3D.js",
43+
"require": "./build/nexus3D.min.js"
44+
},
45+
"./worker": "./build/corto.worker.js"
46+
}
4447
}

nexus3d/rollup.config.js

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,37 @@
11
import { terser } from "rollup-plugin-terser";
22

3-
function header() {
4-
return {
5-
6-
renderChunk( code ) {
7-
return "// vcg.isti.cnr.it/nexus/license\n" + code;
8-
}
9-
};
10-
11-
}
3+
// Helper for license header
4+
const license = "// vcg.isti.cnr.it/nexus/license\n";
125

136
export default [
14-
{
15-
input: './src/Nexus3D.js',
16-
output: [{
17-
format: 'umd',
18-
name: 'Nexus3D',
19-
file: 'build/nexus3D.min.js',
20-
plugins: [terser()],
21-
globals: { three: 'THREE' }
22-
},
23-
{
24-
format: 'umd',
25-
name: 'Nexus3D',
26-
file: 'build/nexus3D.js',
27-
globals: { three: 'THREE' }
28-
}],
29-
external: [ 'three' ]
30-
}
31-
32-
];
7+
// Build the Main Library (Nexus3D)
8+
{
9+
input: './src/Nexus3D.js',
10+
output: [
11+
{
12+
format: 'es',
13+
file: 'build/nexus3D.js',
14+
},
15+
{
16+
format: 'umd',
17+
name: 'Nexus3D',
18+
file: 'build/nexus3D.min.js',
19+
plugins: [terser()],
20+
globals: { three: 'THREE' }
21+
}
22+
],
23+
external: ['three']
24+
},
25+
// Build the Worker (Corto)
26+
{
27+
input: './dist/corto.em.js',
28+
output: {
29+
format: 'iife', // Classic worker format is safest for wide compatibility
30+
file: 'build/corto.worker.js',
31+
plugins: [
32+
terser(),
33+
{ renderChunk: (code) => license + code }
34+
]
35+
}
36+
}
37+
];

nexus3d/src/Cache.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,13 @@ _Cache.prototype = {
5656
setTargetError: function(error) { this.targetError = error; },
5757

5858
loadCorto: function() {
59-
let corto = new Worker(this.cortopath + '/corto.em.js');
59+
let workerPath = this.cortopath + 'corto.worker.js';
60+
try {
61+
workerPath = new URL('./corto.worker.js', import.meta.url).href;
62+
} catch (e) {
63+
//reverrt to es if import.meta.url is not available
64+
}
65+
let corto = new Worker(workerPath);
6066
corto.requests = {};
6167
corto.count = 0;
6268
corto.postRequest = function(node) {

0 commit comments

Comments
 (0)