Created
May 2, 2022 15:21
-
-
Save geoffreynyaga/452f3540d35be05e0ebf16845d30fef9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
yarn add webpack webpack-cli --dev | |
now install babel and other required babel dependencies | |
yarn add @babel/core @babel/preset-react @babel/preset-env --dev | |
Babel Loaders | |
yarn add babel-loader css-loader style-loader --dev | |
install react and react-dom | |
yarn add react react-dom --dev | |
Finally we’ll add a few dependencies that are required for using react-router and class based components in react. | |
yarn add react-router-dom @babel/plugin-proposal-class-properties | |
webpack.config.js | |
``` json | |
const path = require("path"); | |
const webpack = require("webpack"); | |
module.exports = { | |
entry: "./src/index.js", | |
output: { | |
path: path.resolve(__dirname, "./static/ui"), | |
filename: "[name].js", | |
}, | |
resolve: { | |
extensions: [".js", ".jsx", ".json", ".ts", ".tsx"], | |
}, | |
module: { | |
rules: [ | |
{ | |
test: /\.js|.jsx$/, | |
exclude: /node_modules/, | |
use: "babel-loader", | |
}, | |
{ | |
test: /\.(ts|tsx)$/, | |
loader: "ts-loader", | |
}, | |
{ | |
test: /\.css$/, | |
use: ["style-loader", "css-loader"], | |
}, | |
], | |
}, | |
optimization: { | |
minimize: true, | |
}, | |
plugins: [ | |
new webpack.DefinePlugin({ | |
"process.env": { | |
NODE_ENV: JSON.stringify("development"), | |
}, | |
}), | |
], | |
}; | |
``` | |
.babelrc | |
``` json | |
{ | |
"presets": [["@babel/preset-react", { "targets": "defaults" }]], | |
"plugins": ["@babel/plugin-proposal-class-properties"] | |
} | |
``` | |
add these to package.json | |
```json | |
// These are the scripts you should add | |
"scripts": { | |
"dev": "webpack --mode development --watch", | |
"build": "webpack --mode production" | |
}, | |
``` | |
index.js | |
```javascript | |
import React from "react"; | |
import ReactDOM from "react-dom/client"; | |
import App from "./App"; | |
const root = ReactDOM.createRoot(document.getElementById("root")); | |
root.render(<App />); | |
``` | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I got some MIME error... have any idea how i can go about it?