create-react-app <project name>
npm init
npm install -D
npm i webpack webpack-cli -D
npm i babel-core babel-loader babel-preset-env babel-preset-react -D
If you ever encounter an error regarding babel core, install the following dependency.
npm install babel-loader@7 -S
{
"presets": ["env", "react"]
}
module.exports = {
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
}
]
}
};
npm i html-webpack-plugin -D
const HtmlWebPackPlugin = require("html-webpack-plugin");
const htmlPlugin = new HtmlWebPackPlugin({
template: "./public/index.html",
filename: "./index.html"
});
module.exports = {
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
}
]
},
plugins: [htmlPlugin]
};
npm i webpack-dev-server -D
Change the your package.json start script to
"start": "webpack-dev-server --mode development --open"
Install style loader:
npm i css-loader style-loader -D
const HtmlWebPackPlugin = require("html-webpack-plugin");
const htmlWebpackPlugin = new HtmlWebPackPlugin({
template: "./src/index.html",
filename: "./index.html"
});
module.exports = {
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"]
}
]
},
plugins: [htmlWebpackPlugin]
};
npm run build
Make sure you have atleast Python 3.5 first! Save the following as requirements.txt
aiohttp==3.4.4
sanic==0.8.1
run the following command
pip3 install requirements.txt
"start": "python3 server.py",
from sanic import Sanic
from sanic.response import json, html, file, text
import aiohttp
import asyncio
# gets current directory
BASE = os.getcwd()
app = Sanic()
app.static('/src', BASE + '/src')
# serve js file for webpack
app.static('/', BASE)
app.static('/main.js', './dist/main.js', name='main.js')
@app.route('/')
async def index(request):
return await file('./dist/index.html')
if __name__ == '__main__':
app.run(
host='0.0.0.0',
port=int(os.environ.get('PORT', 8000)),
workers=int(os.environ.get('WEB_CONCURRENCY', 1)),
debug=bool(os.environ.get('DEBUG', '')))
npm run start
https://medium.freecodecamp.org/part-1-react-app-from-scratch-using-webpack-4-562b1d231e75