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-serverusing following commandsnpm i -D webpack webpack-clinpm i -D webpack-dev-server - Create
webpack.config.jsfileconst HtmlWebpackPlugin = require('html-webpack-plugin') module.exports = { plugins: [ new HtmlWebpackPlugin({ template: './src/index.html', filename: 'index.html' }) ], }
- Add into
package.jsonforscriptsanddevDependencies"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
TypeScriptcommandnpm i -D typescript ts-loader -
Create
tsconfig.jsonfile and add following{ "compilerOptions": { "target": "ES6", "module": "ES6", "strict": true } } -
Add configurations into the
webpack.config.jsforts-loaderconfigurationsentry: "./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.jsonfile and put following configurations{ "presets": ["@babel/preset-env", "@babel/preset-typescript"] } - Command to install
babel-lodernpm i -D babel-loader - In
webpack.config.jsto replace thets-loaderwithbabel-loaderentry: "./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
pluginconfiguration in the.babelrc.jsonfile.{ "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-pluginfor 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-iconsusingnpm i -S react-icons.
Follow me on - Medium | Linkedin | YouTube | StackOverFlow