This guide is intented to help you getting started with <LiveChatWidget />
in a react application using Webpack 5, TypeScript.
Explaining features/options used below for react, TypeScript, Webpack, Babel are out of scope of this document. Please refer to these open sources official documents for getting more details.
Let’s create the following folders in a root folder:
dist
: This folder will contain all the artifacts from the build output. This will also hold the HTML page where the React app will be injected to.
src
: This will contain source codes.
package.json
In the root of the project, add the following package.json. You can also use npm init
command to create it.
index.html
Let’s also add the following index.html file into the dist
folder. Note the bundle.js
, this JavaScript file will be created after building the react app and will be placed inside dist
folder.
React
and TypeScript
Run the following commands from a command prompt from root folder:
tsconfig.json
TypeScript is configured with a file called tsconfig.json
. Let’s create this file in the root of our project with the following content:
Create a simple React component in a index.tsx
file in the src folder. This will eventually be displayed in index.html
.
Babel
Babel
We'll configure the babel
in .babelrc
file. Create this file under root directory.
Webpack
and toolsWebpack is a bundler tool that can be use to bundle all JavaScript code into the bundle.js file that is used in index.html
.
Install webpack and webpack command line tools:
Webpack also have a web server that can be used during development. To install:
babel-loader
will help to transpile react + TypeScript code to JavaScript. To install:
Webpack
configuration file is JavaScript based as standard, however we can TypeScript as well. To do this use ts-node
.
Webpack
is configured through a configuration file. Create this file in root directory
To build
and run
add below scripts to package.json
Verify the below folder structure after npm run build
Try running the app using npm run start
, you should see a sample page opened in your default browser
After this step, we'll proceed for adding Omnichannel LCW packages
<LiveChatWidget />
to index.tsxThat's all!!!