Skip to content

Instantly share code, notes, and snippets.

@arturproj
Last active April 26, 2021 00:03
Show Gist options
  • Save arturproj/f6cedda29b93d77bb355a448723ae3fb to your computer and use it in GitHub Desktop.
Save arturproj/f6cedda29b93d77bb355a448723ae3fb to your computer and use it in GitHub Desktop.
WebPack 5 basic config -- ReactJs
{
"presets": ["@babel/preset-env", "@babel/preset-react"]
}
{
"scripts": {
"dev": "webpack --mode development",
"build": "webpack --mode production",
"start": "webpack serve --mode development"
},
"devDependencies": {
"@babel/core": "^7.13.16",
"@babel/preset-env": "^7.13.15",
"@babel/preset-react": "^7.13.13",
"babel-loader": "^8.2.2",
"css-loader": "^5.2.4",
"file-loader": "^6.2.0",
"html-webpack-plugin": "^5.3.1",
"sass": "^1.32.11",
"sass-loader": "^11.0.1",
"style-loader": "^2.0.0",
"webpack": "^5.35.0",
"webpack-cli": "^4.6.0",
"webpack-dev-server": "^3.11.2"
},
"dependencies": {
"moment": "^2.29.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-router-dom": "^5.2.0",
}
}

WebPack 5 basic config -- ReactJs

mkdir src && cd src
touch index.html
touch index.js
npm init -y
const HtmlWebpackPlugin = require("html-webpack-plugin");
const path = require("path");
module.exports = {
module: {
rules: [
{
test: /\.(scss|css)$/,
use: ["style-loader", "css-loader", "sass-loader"],
},
{
test: /\.js$/,
exclude: /node_modules/,
use: ["babel-loader"],
},
{
test: /\.(png|jpe?g|gif)$/i,
loader: "file-loader",
options: {
outputPath: "img",
publicPath: "./img",
},
},
],
},
optimization: {
splitChunks: { chunks: "all" },
},
plugins: [
new HtmlWebpackPlugin({
template: path.resolve(__dirname, "src", "index.html"),
}),
],
devServer: {
historyApiFallback: true,
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment