Answer the question
In order to leave comments, you need to log in
How to fix error when running webpack serve?
When I try to start devServer, it gives an error, Google did not help. Thank you.
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const webpack = require('webpack');
module.exports = {
mode: 'development',
devServer: {
static: './',
historyApiFallback: true,
contentBase: path.resolve(__dirname, './dist'),
open: true,
compress: true,
hot: true,
port: 8080,
},
entry: {
main: path.resolve(__dirname, './src/index.js'),
},
output: {
path: path.resolve(__dirname, './dist'),
filename: '[name].bundle.js',
},
plugins: [
new HtmlWebpackPlugin({
title: 'Test PWD',
template: path.resolve(__dirname, './src/template.html'),
filename: 'index.html',
}),
new CleanWebpackPlugin(),
new webpack.HotModuleReplacementPlugin(),
],
module: {
rules: [
// JavaScript
{
test: /\.js$/,
exclude: /node_modules/,
use: ['babel-loader'],
},
{
test: /\.(scss|css)$/,
use: ['style-loader', 'css-loader', 'postcss-loader', 'sass-loader'],
},
],
},
};
Answer the question
In order to leave comments, you need to log in
Approached the solution from https://stackoverflow.com/questions/69117663/webpa...
Proper devserver configuration https://webpack.js.org/configuration/dev-server/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question