-
Make a directory,
mkdir react-ts-webpack
and move into it,cd react-ts-webpack
-
Initialize the project using
npm init -y
which will generate apackage.json
file. -
Make a "src" folder inside,
mkdir src
and move inside it. -
Make a file
index.tsx
, usingtouch index.tsx
inside the "src" folder. -
Go back to the project root directory and add these files,
touch index.html webpack.config.js .babelrc
- Babel is a plugin which is used to transpile our TypeScript code into JavaScript, also the react code into JavaScript.
index.html
will have the basic html 5 boilerplate with a<div id=root></div>
, and a<script src='bundle.js'></script>
.
-
Install following dependencies:
- @babel/core
- @babel/preset-env
- @babel/preset-react
- @babel/preset-typescript
- webpack
- webpack-cli
- webpack-dev-server
- babel-loader
- react
- react-dom
- @types/react
- @types/react-dom
For webpack-dev-server v4+, check the following,
// Instead of
{
"scripts": {
"start" : "webpack-dev-server --open"
}
}
// Do this
{
"scripts" : {
"start" : "webpack-serve --open"
}
}