Webpack-dev-server不重建捆绑

时间:2018-07-31 22:13:15

标签: webpack-dev-server webpack-4 hot-module-replacement

非常奇怪的时刻。 我有:

webpack.hmr.config.js

// webpack.hmr.config.js
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const WebpackChunkHash = require('webpack-chunk-hash');

const commonExportsObject = require('./webpack.common.config');
const commonEnv = commonExportsObject.commonEnv;
const path = require('path');

module.exports = {
  devtool: 'eval-source-map',
  mode: 'development',

  entry: [
    'babel-polyfill',
    'react-hot-loader/patch',
    './src/index',
  ],

  output: {
    path: path.join(__dirname, '/build/'),
    filename: 'main.js',
    publicPath: '/',
  },
  
  resolve: {
    modules: [
      path.join(__dirname, './src'),
      'node_modules',
    ],
  },

  module: {
    rules: [
      {
        test: /\.js$/,
        loaders: [
          {
            loader: 'babel-loader',
            options: {
              babelrc: false,
              presets: ['react', ['es2015', { modules: false }], 'stage-3'],
              plugins: ['react-hot-loader/babel', 'transform-class-properties'],
            },
          },
        ],
        exclude: /node_modules/,
      },
      {
        test: /\.css$/,
        use: ['style-loader', 'css-loader'],
      },
      {
        test: /\.scss$/,
        exclude: /node_modules/,
        use: ['style-loader', 'css-loader', 'sass-loader'],
      },
      {
        test: /\.(png|jpg|gif|eot|ttf|woff|woff2|svg).*$/,
        use: [
          {
            loader: 'file-loader',
            options: {
              name: '[path][name].[ext]',
            },
          },
        ],
      },
    ],
  },

  plugins: [
    new WebpackChunkHash({ algorithm: 'md5' }),
    new HtmlWebpackPlugin({
      inject: 'body',
      filename: 'index.html',
      template: './src/index.html',
    }),
    new webpack.DefinePlugin({
      'process.env': Object.assign({}, commonEnv),
    }),
    new webpack.HotModuleReplacementPlugin(),
  ],

  optimization: {
    namedModules: true,
    noEmitOnErrors: true,
  },
};

server-hmr.js

//server-hmr.js
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');

const config = require('./webpack.hmr.config');

const options = {
  noInfo: true,
  compress: true,
  contentBase: 'build',
  historyApiFallback: true,
  hot: true,
  port: 3000,
  host: 127.0.0.1,
  proxy: [{
    context: ['/api', '/static', '/temp_admin'],
    target: 'http://127.0.0.1:8000/',
    secure: false,
  }],
};

WebpackDevServer.addDevServerEntrypoints(config, options);
const compiler = webpack(config);

new WebpackDevServer(compiler, options).listen(3000, '127.0.0.1', (err) => {
  if (err) {
    console.error(err);
  }
});

运行它: node server-hmr.js

在控制台中: -[HMR]等待来自WDS的更新信号... -[WDS]热模块更换已启用。

我更改了一些文件,但捆绑包未重建。 (很少出现这种情况о_О-文件相同)。

我不知道为什么,请帮助。有什么想法吗?

节点-8.9.1, “ webpack-dev-server”:“ ^ 3.1.5”, “ webpack”:“ ^ 4.16.3”,

1 个答案:

答案 0 :(得分:1)

需要更多内存:

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p