V
V
Vitalik Cherny2021-03-04 06:21:48
Node.js
Vitalik Cherny, 2021-03-04 06:21:48

Why doesn't webpack-server reload the page?

webpack-dev-server doesn't reload page after error in js file.
Other people also meet this problem, but I have not found answers.

Examples:

Webpack dev server stops refresh the page if there...
Webpack-dev-server is not detecting file changes

webpack.config.js

const path = require('path');

// Временная переменная, которая определяет режим сборки.
const { NODE_ENV } = process.env;

// Источник: https://github.com/jantimon/html-webpack-plugin
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  entry: path.resolve(__dirname, './src/js/pages/index.js'),
  // entry: path.resolve(__dirname, './src/index.js'),
  output: {
    path: path.resolve(__dirname, './dist'),
    filename: 'bundle.js',
    // publicPath: '/js/',
  },
  devtool: 'eval-source-map',
  // target: NODE_ENV === 'development' ? 'web' : 'browserslist',
  devServer: {
    contentBase: path.resolve(__dirname, './dist'),
    // publicPath: './js/',
    // contentBase: false,
    historyApiFallback: true,
    open: true,
    // hot: true,
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: './src/index.html',
      filename: 'index.html',
      inject: 'body',
    }),
  ],
};


package.json

{
  "name": "webpack-template",
  "version": "1.0.0",
  "description": "My template",
  "private": true,
  "scripts": {
    "dev": "webpack serve --node-env development",
    "prod": "webpack --node-env production"
  },
  "keywords": [
    "js",
    "webpack"
  ],
  "author": "Devinora <[email protected]>",
  "license": "MIT",
  "homepage": " ",
  "devDependencies": {
    "eslint": "^7.21.0",
    "eslint-config-airbnb-base": "^14.2.1",
    "eslint-plugin-html": "^6.1.1",
    "eslint-plugin-import": "^2.22.1",
    "html-webpack-plugin": "^5.2.0",
    "webpack": "^5.24.3",
    "webpack-cli": "^4.5.0",
    "webpack-dev-server": "^3.11.2",
    "webpack-merge": "^5.7.3"
  }
}


file structure

6040519d2057c668810019.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Just Me, 2021-03-04
@Just__Den

contentBase: './public',

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question