This repository is set for revision of ReacTypeScript for including GraphQL knowledge.
React is a free and open-source front-end JavaScript library for building user interfaces or UI components. It is maintained by Facebook and a community of individual developers and companies. React can be used as a base in the development of single-page or mobile applications.
npx create-react-app my-app --template typescript
Webpack is module bundle for javascript.
- Install
webpack
&webpack-dev-server
using following commandsnpm i -D webpack webpack-cli
npm i -D webpack-dev-server
- Create
webpack.config.js
fileconst HtmlWebpackPlugin = require('html-webpack-plugin') module.exports = { plugins: [ new HtmlWebpackPlugin({ template: './src/index.html', filename: 'index.html' }) ], }
- Add into
package.json
forscripts
anddevDependencies
"scripts": { "build": "webpack --mode production", "start": "webpack-dev-server --open --mode development" }, "devDependencies": { "html-webpack-plugin": "^5.3.2", "webpack": "^5.54.0", "webpack-cli": "^4.8.0", "webpack-dev-server": "^4.2.1" }
-
Install
TypeScript
commandnpm i -D typescript ts-loader
-
Create
tsconfig.json
file and add following{ "compilerOptions": { "target": "ES6", "module": "ES6", "strict": true } }
-
Add configurations into the
webpack.config.js
forts-loader
configurationsentry: "./src/index.ts", resolve: { extensions: ['.js', '.ts', '.tsx'] }, module:{ rules: [{ test: /\.tsx?$/, loader: 'ts-loader', exclude: /node_modules/, }] },
Babel is a JavaScript compiler that includes the ability to compile JSX into regular JavaScript.
- Command to install babel
npm i -D @babel/core @babel/preset-env @babel/preset-typescript
- Create
.babelrc.json
file and put following configurations{ "presets": ["@babel/preset-env", "@babel/preset-typescript"] }
- Command to install
babel-loder
npm i -D babel-loader
- In
webpack.config.js
to replace thets-loader
withbabel-loader
entry: "./src/index.ts", resolve: { extensions: ['.js', '.ts', '.tsx'] }, module:{ rules: [{ test: /\.tsx?$/, loader: 'babel-loader', exclude: /node_modules/, }] },
- Command to install class properties convertor proposal using following command.
npm i -D @babel/plugin-proposal-class-properties
- Need to add
plugin
configuration in the.babelrc.json
file.{ "presets": ["@babel/preset-env", "@babel/preset-typescript"], "plugins": ["@babel/plugin/-proposal-class-properties"] }
- Command to install class properties convertor proposal using following command.
- Run command as
npm i -D css-loader
. - Add following configurations into the
webpack.config.js
module:{
rules: [{
test: /\.tsx?$/,
loader: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.css$/,
loader: 'css-loader'
},
],
},
- Run command as
npm i -D mini-css-extract-plugin
for installing plugin to load css. - Add following configurations into the
webpack.config.js
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
.
.
.
.
module:{
rules: [{
test: /\.tsx?$/,
loader: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, {loader: 'css-loader', options: {modules: true}}],
},
],
},
- Command to install
react-icons
usingnpm i -S react-icons
.
Follow me on - Medium | Linkedin | YouTube | StackOverFlow