We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
使用了 React 项目的代码特征有 JSX 和 Class 语法
// 原 JSX 语法代码 return <h1>Hello,Webpack</h1> // 被转换成正常的 JavaScript 代码 return React.createElement('h1', null, 'Hello,Webpack')
通过以下命令:
# 安装 React 基础依赖 npm i -D react react-dom # 安装 babel 完成语法转换所需依赖 npm i -D babel-preset-react
安装新的依赖后,再修改 .babelrc 配置文件加入 React Presets
"presets": [ "react" ],
tsconfig.json 增加对 JSX 语法的支持,如下:
{ "compilerOptions": { "jsx": "react" // 开启 jsx ,支持 React } }
const path = require('path'); module.exports = { // TS 执行入口文件 entry: './main', output: { filename: 'bundle.js', path: path.resolve(__dirname, './dist'), }, resolve: { // 先尝试 ts,tsx 后缀的 TypeScript 源码文件 extensions: ['.ts', '.tsx', '.js',] }, module: { rules: [ { // 同时匹配 ts,tsx 后缀的 TypeScript 源码文件 test: /\.tsx?$/, loader: 'awesome-typescript-loader' } ] }, devtool: 'source-map',// 输出 Source Map 方便在浏览器里调试 TypeScript 代码 };
npm i react react-dom @types/react @types/react-dom
The text was updated successfully, but these errors were encountered:
No branches or pull requests
使用了 React 项目的代码特征有 JSX 和 Class 语法
通过以下命令:
安装新的依赖后,再修改 .babelrc 配置文件加入 React Presets
tsconfig.json 增加对 JSX 语法的支持,如下:
npm i react react-dom @types/react @types/react-dom
The text was updated successfully, but these errors were encountered: