Skip to content

Commit d506042

Browse files
committed
chore: align build to table-plugin
1 parent 3355437 commit d506042

File tree

2 files changed

+99
-75
lines changed

2 files changed

+99
-75
lines changed

esbuild.config.js

Lines changed: 75 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,75 @@
1-
const esbuild = require('esbuild');
2-
const fs = require('fs');
3-
const path = require('path');
4-
5-
// Build configurations for different module formats
6-
const builds = [
7-
// ES Module (for bundlers like webpack, vite, rollup)
8-
{
9-
entryPoints: ['src/index.js'],
10-
bundle: true,
11-
minify: false,
12-
sourcemap: true,
13-
target: ['es2018'],
14-
format: 'esm',
15-
outfile: 'dist/yasgui-graph-plugin.esm.js',
16-
external: [], // Bundle vis-network
17-
loader: {
18-
'.js': 'js',
19-
},
20-
},
21-
// CommonJS (for Node.js)
22-
{
23-
entryPoints: ['src/index.js'],
24-
bundle: true,
25-
minify: false,
26-
sourcemap: true,
27-
target: ['es2018'],
28-
format: 'cjs',
29-
outfile: 'dist/yasgui-graph-plugin.cjs.js',
30-
external: [], // Bundle vis-network
31-
loader: {
32-
'.js': 'js',
33-
},
34-
},
35-
// IIFE (for browsers via unpkg.com and script tags)
36-
{
37-
entryPoints: ['src/index.js'],
38-
bundle: true,
39-
minify: true,
40-
sourcemap: true,
41-
target: ['es2018'],
42-
format: 'iife',
43-
globalName: 'GraphPlugin',
44-
outfile: 'dist/yasgui-graph-plugin.min.js',
45-
external: [], // Bundle vis-network for browser usage
46-
loader: {
47-
'.js': 'js',
48-
},
49-
},
50-
];
51-
52-
// TypeScript declaration content
53-
const typeDeclaration = `declare module '@matdata/yasgui-graph-plugin';
54-
`;
55-
56-
// Build all formats
57-
Promise.all(builds.map(config => esbuild.build(config)))
58-
.then(() => {
59-
// Create TypeScript declaration file
60-
const distDir = path.join(__dirname, 'dist');
61-
if (!fs.existsSync(distDir)) {
62-
fs.mkdirSync(distDir, { recursive: true });
63-
}
64-
fs.writeFileSync(path.join(distDir, 'index.d.ts'), typeDeclaration);
65-
66-
console.log('✅ Build complete:');
67-
console.log(' - dist/yasgui-graph-plugin.esm.js (ES Module for bundlers)');
68-
console.log(' - dist/yasgui-graph-plugin.cjs.js (CommonJS for Node.js)');
69-
console.log(' - dist/yasgui-graph-plugin.min.js (IIFE for browsers/unpkg)');
70-
console.log(' - dist/index.d.ts (TypeScript declarations)');
71-
})
72-
.catch((err) => {
73-
console.error('❌ Build failed:', err);
74-
process.exit(1);
75-
});
1+
const esbuild = require('esbuild');
2+
const fs = require('fs');
3+
const path = require('path');
4+
5+
// Build configurations for different module formats
6+
const buildConfigs = [
7+
// ES Module (for bundlers like webpack, vite, rollup)
8+
{
9+
entryPoints: ['src/index.js'],
10+
bundle: true,
11+
minify: false,
12+
sourcemap: true,
13+
target: ['es2018'],
14+
format: 'esm',
15+
outfile: 'dist/yasgui-graph-plugin.esm.js',
16+
external: [], // Bundle vis-network
17+
loader: {
18+
'.js': 'js',
19+
},
20+
},
21+
// CommonJS (for Node.js)
22+
{
23+
entryPoints: ['src/index.js'],
24+
bundle: true,
25+
minify: false,
26+
sourcemap: true,
27+
target: ['es2018'],
28+
format: 'cjs',
29+
outfile: 'dist/yasgui-graph-plugin.cjs.js',
30+
external: [], // Bundle vis-network
31+
loader: {
32+
'.js': 'js',
33+
},
34+
},
35+
// IIFE (for browsers via unpkg.com and script tags)
36+
{
37+
entryPoints: ['src/index.js'],
38+
bundle: true,
39+
minify: true,
40+
sourcemap: true,
41+
target: ['es2018'],
42+
format: 'iife',
43+
globalName: 'GraphPlugin',
44+
outfile: 'dist/yasgui-graph-plugin.min.js',
45+
external: [], // Bundle vis-network for browser usage
46+
loader: {
47+
'.js': 'js',
48+
},
49+
},
50+
];
51+
52+
// TypeScript declaration content
53+
const typeDeclaration = `declare module '@matdata/yasgui-graph-plugin';
54+
`;
55+
56+
// Build all formats
57+
Promise.all(buildConfigs.map(config => esbuild.build(config)))
58+
.then(() => {
59+
// Create TypeScript declaration file
60+
const distDir = path.join(__dirname, 'dist');
61+
if (!fs.existsSync(distDir)) {
62+
fs.mkdirSync(distDir, { recursive: true });
63+
}
64+
fs.writeFileSync(path.join(distDir, 'index.d.ts'), typeDeclaration);
65+
66+
console.log('✅ Build complete:');
67+
console.log(' - dist/yasgui-graph-plugin.esm.js (ES Module for bundlers)');
68+
console.log(' - dist/yasgui-graph-plugin.cjs.js (CommonJS for Node.js)');
69+
console.log(' - dist/yasgui-graph-plugin.min.js (IIFE for browsers/unpkg)');
70+
console.log(' - dist/index.d.ts (TypeScript declarations)');
71+
})
72+
.catch((err) => {
73+
console.error('❌ Build failed:', err);
74+
process.exit(1);
75+
});

vite.config.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { defineConfig } from "vite";
2+
import { resolve } from "path";
3+
4+
export default defineConfig({
5+
root: "demo",
6+
publicDir: false,
7+
server: {
8+
host: "0.0.0.0",
9+
port: 5173,
10+
open: false,
11+
},
12+
resolve: {
13+
alias: {
14+
"@matdata/yasgui-graph-plugin": resolve(__dirname, "src/index.js"),
15+
},
16+
extensions: [".ts", ".tsx", ".js", ".jsx", ".json"],
17+
},
18+
build: {
19+
outDir: "../dist",
20+
},
21+
esbuild: {
22+
target: "es2020",
23+
},
24+
});

0 commit comments

Comments
 (0)