$ npm install --save-dev webpack
$ npm install --save-dev webpack-cli
$ npm install --save-dev webpack-dev-server$ npm install --save-dev html-webpack-plugin$ npm install --save-dev style-loader
$ npm install --save-dev css-loader
$ npm install --save-dev mini-css-extract-pluginFirst we need to configure Webpack, create a new file named webpack.config.js
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const path = require("path");
module.exports = {
module: {
rules: [
{
test: /\.css$/i,
use: [MiniCssExtractPlugin.loader, "css-loader"],
}
],
},
plugins: [
new HtmlWebpackPlugin({
template: path.resolve(__dirname, "public", "index.html"),
}),
new MiniCssExtractPlugin(),
],
entry: {
index: path.resolve(__dirname, "source", "index.js"),
},
output: {
path: path.resolve(__dirname, "build"),
},
devServer: {
static: {
directory: path.join(__dirname, 'public'),
},
compress: true,
port: 3000,
},
};Second, create a babel configuration file named babel.config.json
{
"presets": ["@babel/preset-env", "@babel/preset-react"]
}Third, we need to use npm scripts commands in package.json:
{
// omitted configuration
"scripts": {
"start": "webpack serve --mode development --open",
"dev": "webpack --mode development",
"build": "webpack --mode production"
}
// omitted configuration
}We need to add the following configuration to webpack config file
// omitted configuration
module.exports = {
// omitted configuration
optimization: {
splitChunks: { chunks: "all" },
},
// omitted configuration
};$ npm install --save-dev sass
$ npm install --save-dev sass-loader$ npm install --save-dev @babel/core
$ npm install --save-dev @babel/preset-env
$ npm install --save-dev @babel/preset-react
$ npm install --save-dev babel-loaderconst HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const path = require("path");
module.exports = {
module: {
rules: [
{
test: /\.s[ac]ss$/i,
use: [MiniCssExtractPlugin.loader, "css-loader", "sass-loader"],
},
{
test: /\.m?js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-env"],
},
},
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: path.resolve(__dirname, "public", "index.html"),
}),
new MiniCssExtractPlugin(),
],
entry: {
index: path.resolve(__dirname, "source", "index.js"),
},
output: {
path: path.resolve(__dirname, "build"),
},
optimization: {
splitChunks: { chunks: "all" },
},
cache: false,
devServer: {
static: {
directory: path.join(__dirname, 'public'),
},
compress: true,
port: 3000,
},
};