# output.sourcemapPathTransform

类型:
(relativeSourcePath: string, sourcemapPath: string) => string

该选项用于 sourcemap 的路径转换。其中,relativeSourcePath 是指从生成的 .map 文件到相对应的源文件的相对路径,而 sourcemapPath 是指生成 sourcemap 文件的绝对路径。

import path from 'node:path';
export default {
	input: 'src/main',
	output: [
		{
			file: 'bundle.js',
			sourcemapPathTransform: (relativeSourcePath, sourcemapPath) => {
				// 将会把相对路径替换为绝对路径
				return path.resolve(
					path.dirname(sourcemapPath),
					relativeSourcePath
				);
			},
			format: 'es',
			sourcemap: true
		}
	]
};
Last Updated: 6/14/2023, 8:56:23 AM