create-react-app 如何在构建过程中将特定的 .ts 文件编译为 .js 文件?

Posted

技术标签:

【中文标题】create-react-app 如何在构建过程中将特定的 .ts 文件编译为 .js 文件?【英文标题】:create-react-app how to compile specific .ts file to .js file in the build process? 【发布时间】:2020-09-11 13:14:55 【问题描述】:

目前,$ npm run build 将文件从src/ 编译成/build,一切正常。但是,我想将一些特定的 TypeScript 文件 src/integer.ts 编译成它自己的 javascript 文件 build/integer.js 和所有其他要“正常”编译的文件。

这是项目结构:

/src
/build

这是package.json 文件:

"dependencies": 
    "react-scripts": "3.4.1",

...
"scripts": 
     "build": "react-scripts build",

【问题讨论】:

【参考方案1】:

我不明白你的问题。 esnext javascript 和 typescript 都将被编译为 es5。需要什么特别的编译?

【讨论】:

不是一个很好的答案。人们想要这样做的原因有很多。

以上是关于create-react-app 如何在构建过程中将特定的 .ts 文件编译为 .js 文件?的主要内容,如果未能解决你的问题,请参考以下文章

create-react-app npm 运行构建命令

运行 create-react-app 构建脚本时如何设置构建 .env 变量?

使用 create-react-app 和 Typescript 时如何在构建时加载 .md 文件?

如何使 create-react-app 自动构建?

使用 create-react-app 构建后如何修复白屏?

如何运行 create-react-app 构建版本