如何正确配置打字稿映射文件“源”?

时间:2019-02-12 09:40:51

标签: javascript typescript tsconfig

当我将打字稿编译为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)"
}

0 个答案:

没有答案
相关问题