简体   繁体   English

React JS中.tsx文件到.js文件的转换

[英]Conversion of .tsx files into .js file in React JS

I am learning React JS.我正在学习 React JS。 The problem I am facing is that I have bundle of files in.tsx extension so the situation is I want to convert my.tsx files into.js extension for the betterment of my project.我面临的问题是我在 .tsx 扩展名中有一堆文件,所以情况是我想将 my.tsx 文件转换为 .js 扩展名以改进我的项目。 And also, when I'll start the project on browser side and so after compilation It should load the.js files on browser side after compilation.而且,当我将在浏览器端启动项目时,编译后它应该在编译后在浏览器端加载.js文件。 I am using React JS, Typescript and Vite JS for front-end tool.我正在使用 React JS、Typescript 和 Vite JS 作为前端工具。

I am working Ubuntu 18.04我正在工作 Ubuntu 18.04

node.js version == 14.20.0 node.js 版本 == 14.20.0

npm version == 6.14.7 npm 版本 == 6.14.7

and here is my tsconfig.json file:这是我的 tsconfig.json 文件:

{
  "compilerOptions": {
    "target": "ESNext",
    "useDefineForClassFields": true,
    "lib": ["DOM", "DOM.Iterable", "ESNext"],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": false,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "ESNext",
    "moduleResolution": "Node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx"
  },
  "include": ["src"],
  "references": [{ "path": "./tsconfig.node.json" }]
}

Kindly help me to resolve this issue:请帮我解决这个问题:

You just need to use tyescript compiler for converting the tsx in js.您只需要使用 tyescript 编译器来转换 js 中的 tsx。 npx -p typescript tsc somefile.tsx npx -p typescript tsc somefile.tsx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM