@Hakas_Lepehen

Почему нужно автоматически перезагружать страницу при установленном webpack-dev-server?

Имеется конфиг вебпака

const path = require("path");
const HTMLWebpackPlugin = require("html-webpack-plugin");
const {CleanWebpackPlugin} = require("clean-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const OptimizeCssAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const TerserWebpackPlugin = require("terser-webpack-plugin");

console.log(process.env.NODE_ENV);
console.log(__dirname);
const isDev = process.env.NODE_ENV === "development";
const optimization = () => {
    const config = {
        splitChunks: {
            chunks: "all"
        }
    };

    if (!isDev) {
        config.minimizer = [new OptimizeCssAssetsPlugin(), new TerserWebpackPlugin(),];
    }

    return config;
};

const cssLoaders = (extra) => {
    const loaders = [
        {
            loader: MiniCssExtractPlugin.loader,
            options: {
                publicPath: ""
            }
        }, {
            loader: "css-loader"
        },
    ]

    if (extra) {
        loaders.push(extra)
    }

    return loaders;
}

console.log('IsDev:', isDev);

module.exports = {
    context: path.resolve(__dirname),
    entry: path.join(__dirname, "src", "index.js"),
    output:
        {
            filename: "[name].[contenthash].js",
            path: path.resolve(__dirname, "dist")
        },

    optimization: optimization(),

    devServer: {
        port: 4200
    },

    plugins: [
        new HTMLWebpackPlugin(
            {
                title: 'Evermix',
                template: "./index.html",
                minify: {
                    collapseWhitespace: !isDev
                }
            }
        ),
        new CleanWebpackPlugin(),
        new MiniCssExtractPlugin(
            {filename: "[name].[contenthash].css"}
        ),
    ],

    module: {
        rules: [
            {
                test: /\.css$/,
                use: cssLoaders()
            }, {
                test: /\.s[ac]ss$/,
                use: cssLoaders('sass-loader')
            },
            {
                test: /\.(ico|gif|png|jpg|jpeg|svg)$/,
                loader: 'file-loader',
                options: {
                    name: 'src/img/[name].[ext]',
                    publicPath: ''
                }
            },
            {
                test: /\.(ttf|woff|woff2|eot)$/,
                use: [
                    {
                        loader: "file-loader",
                        options: {
                            name: '[name].[ext]',
                            outputPath: 'src/fonts/'
                        }
                    }
                ],
            },
        ]
    }
};


package.json

{
  "name": "GS_1C",
  "version": "1.0.0",
  "description": "project who must help to calculate subscription fee",
  "main": "index.js",
  "scripts": {
    "dev": "cross-env NODE_ENV=development webpack --mode development --watch",
    "build": "cross-env NODE_ENV=production webpack --mode production",
    "watch": " webpack serve --mode development --watch",
    "start": "cross-env NODE_ENV=development webpack serve --mode development --open"
  },
  "repository": {
    "type": "git",
  "devDependencies": {
    "clean-webpack-plugin": "^3.0.0",
    "cross-env": "^7.0.3",
    "css-loader": "^5.0.2",
    "html-webpack-plugin": "^5.1.0",
    "mini-css-extract-plugin": "^1.3.7",
    "optimize-css-assets-webpack-plugin": "^5.0.4",
    "sass": "^1.32.7",
    "sass-loader": "^11.0.1",
    "style-loader": "^2.0.0",
    "terser-webpack-plugin": "^5.1.1",
    "webpack": "^5.22.0",
    "webpack-cli": "^4.5.0",
    "webpack-dev-server": "^3.11.2"
  },
  "dependencies": {
    "bootstrap": "^3.3.6",
    "file-loader": "^6.2.0",
    "normalize.css": "^8.0.1"
  }
}


подскажите, почему при внесении изменений требуется ручная перезагрузка страницы при запуске команды `npm start`?
  • Вопрос задан
  • 32 просмотра
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
от 75 000 до 180 000 ₽
Artezio Нижний Новгород
от 130 000 до 180 000 ₽
Teachbase Москва
До 150 000 ₽