当我将打字稿编译为JavaScript时,.js.map
文件显示出意外的source
(请参见底部代码段)。
如果我要将构建文件夹发布到某个地方(例如npm),它将无法在./src
中看到任何内容。
如何更新地图文件中的源,使其显示类似sources: ['./index.js']
我的文件夹设置:
./build
./build/index.d.ts
./build/index.js
./build/index.js.map
./src
./src/index.ts
./package.json
./tsconfig.json
./yarn.lock
./ tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"declaration": true,
"sourceMap": true,
"outDir": "build",
"lib": ["es2018"],
"resolveJsonModule": true,
"baseUrl": "src",
},
"include": [ "src/**/*.ts" ],
"exclude": [ "node_modules" ]
}
./ src / index.ts
export interface MyType {
myObj: {
one: number
two: string
}
}
export const myObj = {
one: 1,
two: '2',
}
./ build / index.js.map
{
"version":3,
"file":"index.js",
"sourceRoot":"",
"sources": ["../src/index.ts"],
"names": [],
"mappings":"..(removed for brevity)"
}