Skip to content

Commit 1611b7f

Browse files
committed
chore: implement additional entrypoints for npm package
1 parent c69401a commit 1611b7f

File tree

2 files changed

+56
-19
lines changed

2 files changed

+56
-19
lines changed

esbuild.config.js

Lines changed: 53 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,60 @@
11
const esbuild = require('esbuild');
22

3-
// Build configuration
4-
const config = {
5-
entryPoints: ['src/index.js'],
6-
bundle: true,
7-
minify: true,
8-
sourcemap: true,
9-
target: ['es2018'],
10-
format: 'iife',
11-
globalName: 'GraphPlugin',
12-
outfile: 'dist/yasgui-graph-plugin.min.js',
13-
external: [],
14-
// Resolve ES module extensions
15-
loader: {
16-
'.js': 'js',
3+
// Build configurations for different module formats
4+
const builds = [
5+
// ES Module (for bundlers like webpack, vite, rollup)
6+
{
7+
entryPoints: ['src/index.js'],
8+
bundle: true,
9+
minify: false,
10+
sourcemap: true,
11+
target: ['es2018'],
12+
format: 'esm',
13+
outfile: 'dist/yasgui-graph-plugin.esm.js',
14+
external: ['vis-network'], // Don't bundle vis-network for ESM
15+
loader: {
16+
'.js': 'js',
17+
},
1718
},
18-
};
19+
// CommonJS (for Node.js)
20+
{
21+
entryPoints: ['src/index.js'],
22+
bundle: true,
23+
minify: false,
24+
sourcemap: true,
25+
target: ['es2018'],
26+
format: 'cjs',
27+
outfile: 'dist/yasgui-graph-plugin.cjs.js',
28+
external: ['vis-network'], // Don't bundle vis-network for CJS
29+
loader: {
30+
'.js': 'js',
31+
},
32+
},
33+
// IIFE (for browsers via unpkg.com and script tags)
34+
{
35+
entryPoints: ['src/index.js'],
36+
bundle: true,
37+
minify: true,
38+
sourcemap: true,
39+
target: ['es2018'],
40+
format: 'iife',
41+
globalName: 'GraphPlugin',
42+
outfile: 'dist/yasgui-graph-plugin.min.js',
43+
external: [], // Bundle vis-network for browser usage
44+
loader: {
45+
'.js': 'js',
46+
},
47+
},
48+
];
1949

20-
esbuild
21-
.build(config)
22-
.then(() => console.log('✅ Build complete: dist/yasgui-graph-plugin.min.js'))
50+
// Build all formats
51+
Promise.all(builds.map(config => esbuild.build(config)))
52+
.then(() => {
53+
console.log('✅ Build complete:');
54+
console.log(' - dist/yasgui-graph-plugin.esm.js (ES Module for bundlers)');
55+
console.log(' - dist/yasgui-graph-plugin.cjs.js (CommonJS for Node.js)');
56+
console.log(' - dist/yasgui-graph-plugin.min.js (IIFE for browsers/unpkg)');
57+
})
2358
.catch((err) => {
2459
console.error('❌ Build failed:', err);
2560
process.exit(1);

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"private": false,
44
"version": "0.1.0",
55
"description": "YASGUI plugin for visualizing SPARQL CONSTRUCT and DESCRIBE query results as interactive graphs",
6-
"main": "dist/yasgui-graph-plugin.min.js",
6+
"main": "dist/yasgui-graph-plugin.cjs.js",
7+
"module": "dist/yasgui-graph-plugin.esm.js",
8+
"unpkg": "dist/yasgui-graph-plugin.min.js",
79
"files": [
810
"dist",
911
"README.md",

0 commit comments

Comments
 (0)