gpt4 book ai didi

javascript - 如何使用 Yarn 将 TypeScript 转换为 JavaScript?

转载 作者:行者123 更新时间:2023-12-02 02:46:43 25 4
gpt4 key购买 nike

如何在由 Yarn 管理的项目中将 TypeScript 代码转换为 JavaScript?

我需要 Javascript 代码以便与其他编译器(例如 GraalVM)一起运行它并研究性能。

最佳答案

您可以通过将构建规则添加到您的 package.json 来实现。

{
"name": "my-package",
"scripts": {
"build": "tsc -p .",
}
}

. 替换为您的 tsconfig.json 文件的路径,例如,该文件包含以下行。

{
"compilerOptions": {
"target": "ES2019", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
"outDir": "./dist", /* Redirect output structure to the directory. */
"strict": true, /* Enable all strict type-checking options. */
"strictNullChecks": true, /* Enable strict null checks. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
}
}

运行 yarn run build

转译后的 JavaScript 文件将在 ./dist 目录中。

关于javascript - 如何使用 Yarn 将 TypeScript 转换为 JavaScript?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62662558/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com