-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.mjs
More file actions
43 lines (35 loc) · 1.21 KB
/
build.mjs
File metadata and controls
43 lines (35 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// build.mjs
import { readFile, writeFile, copyFile } from 'fs/promises';
const input = 'src/ftable.js'; // Your source
const outputEsm = 'ftable.esm.js';
const outputUmd = 'ftable.umd.js';
const outputStandalone = 'ftable.js'; // ← This is the standalone version
const source = await readFile(input, 'utf8');
// ESM version
const esm = `
${source}
export default FTable;
`;
await writeFile(outputEsm, esm);
// UMD version
const umd = `
(function (global) {
${source}
// Expose classes globally
global.FTable = FTable;
global.FtableModal = FtableModal;
global.FTableHttpClient = FTableHttpClient;
// For CommonJS
if (typeof module !== 'undefined' && module.exports) {
module.exports = FTable;
module.exports.FtableModal = FtableModal;
module.exports.FTableHttpClient = FTableHttpClient;
}
}(typeof globalThis !== 'undefined' ? globalThis :
typeof window !== 'undefined' ? window :
typeof global !== 'undefined' ? global : this));
`;
await writeFile(outputUmd, umd);
// ✅ Make ftable.js the standalone/UMD version (for backward compatibility)
await copyFile(outputUmd, outputStandalone);
console.log('✅ Built ftable.js (standalone), ftable.esm.js, ftable.umd.js');