egoist / tsup

The simplest and fastest way to bundle your TypeScript libraries.
https://tsup.egoist.dev
MIT License
8.46k stars 209 forks source link

SourceMap Not Linked When Enabled #1120

Open jd-carroll opened 1 month ago

jd-carroll commented 1 month ago

Under a very specific circumstance, the generated output from esbuild does not contain the //# sourceMappingURL= reference.

If you write a simple plugin to rename the files on end, example below, the output does not contain the source map link.

However, if I go into node_modules and force the esbuild sourcemap input to be:

sourcemap: 'linked',

It will work as expected.

Please update the types of sourcemap to be:

sourcemap?: boolean | 'inline' | 'linked';

With an implementation of:

sourcemap: options.sourcemap === true 
  ? "external" 
  : typeof options.sourcemap === 'string' 
    ? options.sourcemap 
    : false,

Here is an example plugin (you'll need to adapt for a working example):

const RenameOnEnd: Plugin = {
  name: 'rename-on-end',
  setup(build) {
    build.onEnd((result) => {
      for (const file of result.outputFiles || []) {
        if (file.path.endsWith('.js.map')) {
          continue;
        }
        file.path = file.path + '.special.js';
      }
    });
  }
};

export default defineConfig({
  entry: ['lambdas/*/*-handler.ts'],
  splitting: true,
  target: 'esnext',
  sourcemap: true,
  format: ['esm'],
  clean: true,
  outDir: 'dist/lambdas',
  esbuildPlugins: [RenameOnEnd],
});

Related Issues:

775

495

Upvote & Fund

Fund with Polar