Terser - 当原始地图文件还包含源时如何包含源?
Terser - How to includeSources when original map file also contains source?
我正在构建 index.js 使用打字稿转译器,它生成 index.js.map 包含原始打字稿文件。
我现在想压缩该文件并将原始源保留在 index.js.map 文件中,这样我就可以单步执行打字稿代码而不是转译后的代码。
我的剧本运行:
terser index.js --source-map \"url='./index.js.map',includeSources\" -o index.js -c
将 index.js 替换为压缩版本,并将 index.js.map 文件替换为转译后的源代码,而不是原始打字稿源代码。 terser 是否能够在 sourcemap 文件中保留源代码?
答案在文档中很容易找到:
Composed source map When you're compressing JS code that was output by
a compiler such as CoffeeScript, mapping to the JS code won't be too
helpful. Instead, you'd like to map back to the original code (i.e.
CoffeeScript). Terser has an option to take an input source map.
Assuming you have a mapping from CoffeeScript → compiled JS, Terser
can generate a map from CoffeeScript → compressed JS by mapping every
token in the compiled JS to its original location.
To use this feature pass --source-map
"content='/path/to/input/source.map'" or --source-map "content=inline"
if the source map is included inline with the sources.
我正在构建 index.js 使用打字稿转译器,它生成 index.js.map 包含原始打字稿文件。
我现在想压缩该文件并将原始源保留在 index.js.map 文件中,这样我就可以单步执行打字稿代码而不是转译后的代码。
我的剧本运行:
terser index.js --source-map \"url='./index.js.map',includeSources\" -o index.js -c
将 index.js 替换为压缩版本,并将 index.js.map 文件替换为转译后的源代码,而不是原始打字稿源代码。 terser 是否能够在 sourcemap 文件中保留源代码?
答案在文档中很容易找到:
Composed source map When you're compressing JS code that was output by a compiler such as CoffeeScript, mapping to the JS code won't be too helpful. Instead, you'd like to map back to the original code (i.e. CoffeeScript). Terser has an option to take an input source map. Assuming you have a mapping from CoffeeScript → compiled JS, Terser can generate a map from CoffeeScript → compressed JS by mapping every token in the compiled JS to its original location.
To use this feature pass --source-map "content='/path/to/input/source.map'" or --source-map "content=inline" if the source map is included inline with the sources.