Languages & Frameworks

问题描述 投票:0回答:2

我们正在使用WebStorm和TypeScript项目。我们使用tsconfig.json正确地配置了项目,因为一切都在命令行中正常工作。

然而,当在WebStorm中打开项目时,它在原地编译ts文件(它生成的js文件与相应的ts文件在同一个文件夹中),而tsconfig说它应该在 dist dir。

例如,在下面的截图中。evaluator.js 是在同一个文件夹中 evaluator.ts 文件。知道如何配置WebStorm,使其不在原地生成js文件吗?

enter image description here

这里是Typescript的首选项。

enter image description here

这里是tsconfig.json文件。

{
  "compilerOptions": {
    "allowJs": true,
    "allowSyntheticDefaultImports": true,
    "charset": "utf-8",
    "declaration": true,
    "experimentalDecorators": true,
    "module": "commonjs",
    "moduleResolution": "node",
    "outDir": "dist",
    "pretty": false,
    "rootDir": "src",
    "sourceMap": true,
    "strict": true,
    "stripInternal": true,
    "target": "es2016",
    "typeRoots": ["node_modules/@types"],
    "types": ["node", "jest"],
    "lib": [
      "es2019"
    ]
  },
  "include": ["src/**/*.ts", "src/**/*.js", "src/index.ts"],
  "exclude": ["node_modules"]
}
typescript webstorm
2个回答
0
投票

你需要这样的东西在你的 package.json

...
  "main": "app/src/index.js",
  "scripts": {
    "copyjson": "copyfiles 'src/**/*.json' app",
    "copyhbs": "copyfiles 'src/**/*.hbs' app",
    "copyhtml": "copyfiles 'src/**/*.html' app",
    "prebuild": "tslint -c tslint.json -p tsconfig.json --fix",
    "build": "tsc && npm run copyjson && npm run copyhbs && npm run copyhtml",
    "prestart": "npm run build",
    "start": "node app/src/index"
  }
...

然后

npm install
npm run build
npm run start

0
投票

显然,Webstorm是独立地将typescript文件转移到javascript中的。

确保 "启用TypeScript编译器 "在首选项中被禁用。

© www.soinside.com 2019 - 2024. All rights reserved.