[英]Output folder for compiled TypeScript
I'm following a tutorial called THE HERO EDITOR, and it has me creating and editing TypeScript files in an app
folder. 我正在关注一个名为THE HERO EDITOR的教程,它让我在
app
文件夹中创建和编辑TypeScript文件。 The app uses a script tsc -w
, where the w
causes the tsc
transpiler to output a new JavaScript file every time a TypeScript file fails. 该应用程序使用脚本
tsc -w
,其中w
使得tsc
转换器在每次TypeScript文件失败时输出新的JavaScript文件。
This caused me some confusion for several minutes, because when I added a TypeScript class, the editor (Visual Studio Code) underlined the class name and told me it was a duplicate declaration. 这引起了我几分钟的困惑,因为当我添加一个TypeScript类时,编辑器(Visual Studio Code)为类名加下划线并告诉我它是一个重复的声明。 I saw the JavaScript file with the same name, but no sooner had I deleted it, the duplicate declaration, and thus the JS file, were back.
我看到了同名的JavaScript文件,但是我刚刚删除它,重复声明,因此JS文件又回来了。
The script is declared in package.json
: 该脚本在
package.json
声明:
"scripts": {
"start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",
"tsc": "tsc",
"tsc:w": "tsc -w",
},
Where can I specify where compiled JavaScript goes? 我在哪里可以指定编译JavaScript的位置? I doubt I can do it here, but I can only guess that I need a
grunt
or equivalent file, but then what do I do in that file, and do I remove the tsc
entries from `package.js' once another file takes over? 我怀疑我能在这里做到这一点,但我只能猜测我需要一个
grunt
或等效文件,但是我该怎么办在那个文件中,一旦另一个文件接管我是否从`package.js'中删除tsc
条目?
We can control where our compiled javascript goes with the help of "outDir
" parameter of "compilerOptions"
in our tsconfig.json
file. 我们可以在
tsconfig.json
文件中使用"compilerOptions"
的"outDir
”参数来控制编译的javascript所在的位置。
I am also using Visual Studio Code and I generally create my tsconfig.json
file at the project root directory. 我也在使用Visual Studio Code,我通常在项目根目录下创建我的
tsconfig.json
文件。 Here is an example, where I want my compiled javascript to go inside "src/ts-out/"
directory 这是一个例子,我希望我编译的javascript进入
"src/ts-out/"
目录
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"sourceMap": true,
"outDir": "src/ts-out/"
}
}
Hope it helps. 希望能帮助到你。 Happy coding...
快乐的编码......
据我所知,编译后的ts文件保存在与ts文件相同的文件夹中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.