Skip to content

Commit bf15062

Browse files
committed
chore: align build with graph plugin
1 parent 19ac286 commit bf15062

File tree

10 files changed

+3089
-2258
lines changed

10 files changed

+3089
-2258
lines changed

.eslintrc.js

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,17 @@
11
module.exports = {
2-
root: true,
3-
parser: '@typescript-eslint/parser',
2+
env: {
3+
browser: true,
4+
es2018: true,
5+
},
6+
extends: ['eslint:recommended'],
47
parserOptions: {
58
ecmaVersion: 2018,
69
sourceType: 'module',
7-
project: './tsconfig.json'
8-
},
9-
plugins: ['@typescript-eslint'],
10-
extends: [
11-
'eslint:recommended',
12-
'plugin:@typescript-eslint/recommended'
13-
],
14-
ignorePatterns: ['*.config.js', 'dist', 'node_modules'],
15-
env: {
16-
browser: true,
17-
es6: true,
18-
node: true
1910
},
2011
rules: {
21-
'@typescript-eslint/no-explicit-any': 'warn',
22-
'@typescript-eslint/explicit-function-return-type': 'off',
23-
'@typescript-eslint/no-unused-vars': ['error', {
24-
argsIgnorePattern: '^_',
25-
varsIgnorePattern: '^_'
26-
}],
27-
'no-console': ['warn', { allow: ['warn', 'error'] }]
28-
}
12+
'no-console': ['warn', { allow: ['warn', 'error'] }],
13+
'no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
14+
'prefer-const': 'error',
15+
'no-var': 'error',
16+
},
2917
};

.npmignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Development and demo files
2+
demo/
3+
example/
4+
.vscode/
5+
.specify/
6+
specs/
7+
*.sparql
8+
9+
# Source files (publish only dist/)
10+
src/
11+
esbuild.config.js
12+
.eslintrc.js
13+
.prettierrc
14+
15+
# Dependencies
16+
node_modules/
17+
18+
# Git and config files
19+
.git/
20+
.gitignore
21+
.github/

CHANGELOG.md

Lines changed: 0 additions & 25 deletions
This file was deleted.

esbuild.config.js

Lines changed: 84 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import * as esbuild from 'esbuild';
2-
import { readFileSync, writeFileSync, mkdirSync } from 'fs';
3-
import { resolve, dirname } from 'path';
4-
import postcss from 'postcss';
5-
import postcssImport from 'postcss-import';
6-
import cssnano from 'cssnano';
1+
2+
const esbuild = require('esbuild');
3+
const fs = require('fs');
4+
const path = require('path');
5+
6+
const postcss = require('postcss');
7+
const postcssImport = require('postcss-import');
8+
const cssnano = require('cssnano');
79

810
const production = process.env.NODE_ENV === 'production';
911

@@ -12,7 +14,7 @@ const cssPlugin = {
1214
name: 'css',
1315
setup(build) {
1416
build.onLoad({ filter: /\.css$/ }, async (args) => {
15-
const css = readFileSync(args.path, 'utf8');
17+
const css = fs.readFileSync(args.path, 'utf8');
1618

1719
// Process CSS with PostCSS
1820
const result = await postcss([
@@ -29,79 +31,88 @@ const cssPlugin = {
2931
};
3032

3133
// Build configuration
32-
const baseConfig = {
33-
entryPoints: ['src/index.ts'],
34-
bundle: true,
35-
external: ['@yasgui/yasr', '@yasgui/utils', 'tabulator-tables'],
36-
sourcemap: true,
37-
target: 'es2020',
38-
plugins: [cssPlugin],
39-
};
40-
41-
async function build() {
42-
try {
43-
// Create dist directory
44-
mkdirSync('dist', { recursive: true });
45-
mkdirSync('dist/types', { recursive: true });
46-
47-
// Build UMD format
48-
await esbuild.build({
49-
...baseConfig,
50-
outfile: 'dist/yasgui-table-plugin.umd.js',
51-
format: 'iife',
52-
globalName: 'YasguiTablePlugin',
53-
footer: {
54-
js: 'if (typeof module !== "undefined" && module.exports) { module.exports = YasguiTablePlugin; }'
55-
},
56-
});
34+
const buildConfigs = [
35+
// ES Module (for bundlers like webpack, vite, rollup)
36+
{
37+
entryPoints: ['src/index.ts'],
38+
bundle: true,
39+
minify: false,
40+
sourcemap: true,
41+
target: ['es2018'],
42+
format: 'esm',
43+
outfile: 'dist/yasgui-table-plugin.esm.js',
44+
external: [],
45+
loader: {
46+
'.js': 'js',
47+
},
48+
plugins: [cssPlugin],
49+
},
50+
// CommonJS (for Node.js)
51+
{
52+
entryPoints: ['src/index.ts'],
53+
bundle: true,
54+
minify: false,
55+
sourcemap: true,
56+
target: ['es2018'],
57+
format: 'cjs',
58+
outfile: 'dist/yasgui-table-plugin.cjs.js',
59+
external: [],
60+
loader: {
61+
'.js': 'js',
62+
},
63+
plugins: [cssPlugin],
64+
},
65+
// IIFE (for browsers via unpkg.com and script tags)
66+
{
67+
entryPoints: ['src/index.ts'],
68+
bundle: true,
69+
minify: true,
70+
sourcemap: true,
71+
target: ['es2018'],
72+
format: 'iife',
73+
globalName: 'TablePlugin',
74+
outfile: 'dist/yasgui-table-plugin.min.js',
75+
external: [],
76+
loader: {
77+
'.js': 'js',
78+
},
79+
plugins: [cssPlugin],
80+
},
81+
];
5782

58-
// Build ESM format
59-
await esbuild.build({
60-
...baseConfig,
61-
outfile: 'dist/yasgui-table-plugin.esm.js',
62-
format: 'esm',
63-
});
83+
// TypeScript declaration content
84+
const typeDeclaration = `declare module '@matdata/yasgui-table-plugin';
85+
`;
6486

65-
// Build minified version in production
66-
if (production) {
67-
await esbuild.build({
68-
...baseConfig,
69-
outfile: 'dist/yasgui-table-plugin.min.js',
70-
format: 'iife',
71-
globalName: 'YasguiTablePlugin',
72-
minify: true,
73-
footer: {
74-
js: 'if (typeof module !== "undefined" && module.exports) { module.exports = YasguiTablePlugin; }'
75-
},
76-
});
87+
// Build all formats
88+
Promise.all(buildConfigs.map(config => esbuild.build(config)))
89+
.then(() => {
90+
// Create TypeScript declaration file
91+
const distDir = path.join(__dirname, 'dist');
92+
if (!fs.existsSync(distDir)) {
93+
fs.mkdirSync(distDir, { recursive: true });
7794
}
7895

7996
// Build CSS bundle
80-
const cssContent = readFileSync('styles/index.css', 'utf8');
81-
const cssResult = await postcss([
97+
const cssContent = fs.readFileSync('styles/index.css', 'utf8');
98+
return postcss([
8299
postcssImport(),
83100
...(production ? [cssnano()] : [])
84-
]).process(cssContent, { from: 'styles/index.css' });
85-
86-
writeFileSync('dist/yasgui-table-plugin.css', cssResult.css);
101+
]).process(cssContent, { from: 'styles/index.css' })
102+
.then((cssResult) => {
103+
fs.writeFileSync('dist/yasgui-table-plugin.css', cssResult.css);
104+
fs.writeFileSync(path.join(distDir, 'index.d.ts'), typeDeclaration);
87105

88-
console.log('Build completed successfully!');
89-
} catch (error) {
90-
console.error('Build failed:', error);
106+
console.log('✅ Build complete:');
107+
console.log(' - dist/yasgui-table-plugin.esm.js (ES Module for bundlers)');
108+
console.log(' - dist/yasgui-table-plugin.cjs.js (CommonJS for Node.js)');
109+
console.log(' - dist/yasgui-table-plugin.min.js (IIFE for browsers/unpkg)');
110+
console.log(' - dist/yasgui-table-plugin.css (Bundled CSS)');
111+
console.log(' - dist/index.d.ts (TypeScript declarations)');
112+
});
113+
})
114+
.catch((err) => {
115+
console.error('❌ Build failed:', err);
91116
process.exit(1);
92-
}
93-
}
94-
95-
// Watch mode
96-
if (process.argv.includes('--watch')) {
97-
const ctx = await esbuild.context({
98-
...baseConfig,
99-
outfile: 'dist/yasgui-table-plugin.esm.js',
100-
format: 'esm',
101117
});
102-
103-
await ctx.watch();
104-
console.log('Watching for changes...');
105-
} else {
106-
build();
107-
}
118+

0 commit comments

Comments
 (0)