Webpack开发服务器无法在保存时重新加载

5

我正在尝试建立一个项目,但似乎无法让webpack在保存项目时刷新。

它似乎根本不重新编译bundle.js,而且我已经重新运行脚本以跟踪任何更改。

下面是我的webpack配置和package.json文件中的scripts部分。

webpack.config.js

const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');

module.exports =  {
    entry: "./src/index.js",
    mode: "none",
    output: {
        path: path.resolve(__dirname, './dist'),
        filename: 'bundle.js'
    },
    module: {
        rules: [
            {
                test: /\.(js|jsx)$/,
                exclude: /node_modules/,
                loader: "babel-loader"
            },
            {
                test:/\.(s*)css$/,
                use:[
                    'style-loader?sourceMap',
                    'css-loader?modules&importLoaders=1&localIdentName=[path]___[name]__[local]___[hash:base64:5]',
                    'sass-loader'
                ]
            },
            {
                test: /\.(png|jpg)$/,
                loader: 'url-loader?limit=8192&name=images/[name].[ext]',
            }
        ],
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: "./src/templates/index.html"
        })
    ]
};

从package.json运行的脚本
  "scripts": {
    "build": "webpack",
    "dev": "webpack-dev-server --config ./webpack.config.js"
  },
2个回答

3

安装webpack-cli以启用你的应用程序中的HMR(热模块替换)。

然后在你的dev脚本中添加--hot:

"dev": "webpack-dev-server --config ./webpack.config.js --hot"

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接