27 lines
978 B
TypeScript
27 lines
978 B
TypeScript
import path from 'path';
|
|
import { createLibraryConfig } from '@lilith/configs/tsup/library';
|
|
|
|
// NodeDictionaryLoader and DictionaryPersistence import fs/path/fs/promises.
|
|
// These are dead code in browser consumers, but esbuild keeps the import
|
|
// statements for external modules. Solution:
|
|
// 1. noExternal prevents fs/path from landing in the external list
|
|
// 2. alias redirects them to a browser-safe stub that bundles inline
|
|
// Result: no bare `import * as fs from 'fs'` statements in the dist output.
|
|
const stubPath = path.resolve('./src/browser-stubs/node-modules.ts');
|
|
|
|
export default createLibraryConfig({
|
|
noExternal: ['fs', 'path', 'os', 'fs/promises'],
|
|
esbuildOptions(options) {
|
|
options.alias = {
|
|
...options.alias,
|
|
'fs': stubPath,
|
|
'path': stubPath,
|
|
'os': stubPath,
|
|
'fs/promises': stubPath,
|
|
'node:fs': stubPath,
|
|
'node:path': stubPath,
|
|
'node:os': stubPath,
|
|
'node:fs/promises': stubPath,
|
|
};
|
|
},
|
|
});
|