import { PluginBuild } from 'esbuild' import path from 'path' import ts from 'typescript' import fs from 'fs' interface PluginOptions { paths?: ts.CompilerOptions['paths'] } export const pathsLoadPlugin = (options: PluginOptions) => { return { name: 'tsconfig paths load plugin', setup(build: PluginBuild) { build.onLoad({ filter: /\.ts$/ }, async (args) => { let text = await fs.promises.readFile(args.path, 'utf8') return { contents: text.replace(/@lib/, 'QQQ'), loader: 'ts', } }) }, } }