Reputation: 348
We are using WebStorm with TypeScript project. We have configured project correctly using tsconfig.json as everything works correctly from command line.
However, when opened the project in WebStorm, it compiles the ts files in place (it generates js file in same folder as corresponding ts file) where as tsconfig says it should be in dist
dir.
For example, in below screenshot, evaluator.js
is in same folder as evaluator.ts
file. Any idea how to configure WebStorm such that it doesn't generate js files in place?
Here are Typescript preferences.
Here is the tsconfig.json file
{
"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"]
}
Upvotes: 2
Views: 1558
Reputation: 162
I had the same issue. However for me the problem was that when I ran my unit tests the newest version of the code was not reflected in the transpiled files. Could not find a way to fix it from webstorms settings. So in the end I just ended up adding a yarn target to remove all of the generated files in source. I can then run this before I run the tests to make sure that I get a freshly transpiled version. The script in package.json looks like this:
"scripts": {
"clear-cache": "find src -type f \\( -name \"*.js\" -o -name \"*.d.ts.map\" -o -name \"*.d.ts\" \\) -exec rm {} \\;",
},
Doesn't really solved the original problem, but it was as close as I was able to get.
Upvotes: 0
Reputation: 11305
Apparently Webstorm transpiles typescript files to javascript independently
Make sure that 'Enable TypeScript compiler' is disabled in Preferences | Languages & Frameworks | TypeScript, and that you don't have TypeScript file watcher set up in Preferences | Tools | File Watchers
Upvotes: 3
Reputation: 1593
you need something like this in your 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"
}
...
then do a
npm install
npm run build
npm run start
Upvotes: -1