5

I'm using combination of TypeScript and Rollup as is presented in this article.

Thus math.ts

export function square(x: number) {
    return x ** 2;
}

export function cube(x: number) {
    return x ** 3;
}

and main.ts

import { square } from "./math";

console.log(square(3));

generates after command

tsc -t ES5 -m es2015 && rollup -f es -o app.js -m -i main.js

file app.js

function square(x) {
    return Math.pow(x, 2);
}

console.log(square(3));
//# sourceMappingURL=app.js.map

But the generated source map points to the .js output of tsc, not the original .ts files. How can I get the latter?

Inigo
  • 12,186
  • 5
  • 41
  • 70
Matěj Pokorný
  • 16,977
  • 5
  • 39
  • 48

1 Answers1

2

Yes. Try rollup-plugin-sourcemaps.

Follow the usage at the above link.

Or checkout Alex Jover's typescript-library-starter which uses the this plugin as well as others that might solve other problems for you. He also says:

If you use rollup-plugin-babel, you might be able to use the inputSourceMap option instead of this plugin.

Inigo
  • 12,186
  • 5
  • 41
  • 70
  • This is my rollup-plugin-sourcefile result map file - `{"version":3,"file":"index.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}`. The man page doesn't actually say it can bundle map files - maybe it requires there be only one file being bundled? – Craig Hicks Mar 06 '22 at 14:19
  • 1
    Unfortunately, it seems `rollup-plugin-sourcemaps` is no longer being maintained, e.g. it depends on deprecated packages and a [PR](https://github.com/maxdavidson/rollup-plugin-sourcemaps/pull/123) submitted to fix the issue has been sitting idle for several weeks :-( – Eric Mutta Dec 21 '22 at 22:47