-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtsup.config.ts
More file actions
50 lines (46 loc) · 1.48 KB
/
tsup.config.ts
File metadata and controls
50 lines (46 loc) · 1.48 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
44
45
46
47
48
49
50
import { defineConfig } from 'tsup';
const pyodideDependencies = [
'pyodide-lock.json',
'pyodide.asm.wasm',
'pyodide.asm.js',
];
export default defineConfig({
entry: ['src/index.ts'],
format: ['cjs', 'esm', 'iife'], // CommonJS, ES Modules, and Browser IIFE
globalName: 'Aksharamukha', // For browsers (window.Aksharamukha)
dts: true, // Generate .d.ts types
sourcemap: true,
minify: true,
clean: true,
esbuildOptions: options => {
if (options.format !== 'esm') {
options.logOverride = {
'empty-import-meta': 'silent'
};
}
if (options.format === 'iife') {
// Add currentScript reference and window.Aksharamukha point to the default export
options.footer = {
js: `
Object.assign(window, { ${options.globalName}: ${options.globalName}.default });
window.${options.globalName}._setCurrentScript(document.currentScript);
`
};
}
},
onSuccess: async () => {
// Copy everything from downloads to dist
const fs = await import('fs');
const files = fs.lstatSync('./downloads', { throwIfNoEntry: true });
if (!files.isDirectory()) {
throw new Error('./downloads is not a directory.');
}
fs.cpSync('./downloads', './dist', { recursive: true });
const pyodideFiles = fs.readdirSync('./node_modules/pyodide');
for (const file of pyodideFiles) {
if (file.endsWith('.whl') || file.endsWith('.zip') || pyodideDependencies.includes(file)) {
fs.cpSync(`./node_modules/pyodide/${file}`, `./dist/${file}`);
}
}
}
});