Webpack HotModuleReplacementPlugin在更改文件时不更新页面

时间:2016-07-15 01:15:23

标签: javascript webpack webpack-dev-server webpack-hmr

页面正确加载,甚至记录到客户端控制台[WDS] Hot module replacement enabled。但是当我对文件进行更改时,页面上没有反映出任何内容。即使重装也是如此。仅在重新启动服务器时。

不确定是否这件事,但我使用的是redux。

webpack.config.js

var precss = require('precss');
var autoprefixer = require('autoprefixer');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  devtool: 'eval-source-map',
  entry: __dirname + '/src/index.js',
  output: {
    path: __dirname + '/build',
    filename: 'bundle.js',
  },
  module: {
    loaders: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: 'babel'
      },
      {
        test: /\.json$/,
        loader: 'json-loader'
      },
      {
        test: /\.css$/,
        loader: 'style!css?modules!postcss'
      },
      { 
        test: /\.(png|jpg|jpeg|gif|woff)$/, 
        loader: 'url-loader?limit=8192' 
      }
    ]
  },

  postcss: function() {
    return [autoprefixer, precss];
  },

  plugins: [
    new HtmlWebpackPlugin({
      template: __dirname + '/src/index.html'
    }),
    new webpack.HotModuleReplacementPlugin()
  ],

  devServer: {
    contentBase: './public',
    colors: true,
    historyApiFallback: true,
    inline: true,
    hot: true
  },

  jest: {
    moduleFileExtensions: ["js", "jsx"]
  }
};

.babelrc

{
  "presets": ["react", "es2015", "stage-0"],
  "env": {
    "development": {
      "plugins": [["react-transform", {
        "transforms": [{
          "transform": "react-transform-hmr",
          "imports": ["react"],
          // this is important for Webpack HMR:
          "locals": ["module"]
        }]
        // note: you can put more transforms into array
        // this is just one of them!
      }]]
    }
  }
}

2 个答案:

答案 0 :(得分:0)

尝试添加

"scripts": {
    "start": "node_modules/.bin/webpack-dev-server --progress --inline"
},
在package.json文件中

,并使用npm start

答案 1 :(得分:0)

在webpack配置中添加额外的入口点会自动重新加载页面,但是由于刷新,您将失去所有状态。

Content = new StackLayout 
{
    Children 
    {
        new CmButton 
        {
            Text = "SIGN UP| AGREE TO TERMS",
            BackgroundColor = Color.Transparent,
            BorderColor = Color.Transparent,
            BorderWidth = 0,
            TextColor = Color.White
        }
    }
}

并在服务器js中

 Add a class named yourradio in your radio button and add this javascript 
<label class='with-square-checkbox2-mylist-details'>
      <input type='checkbox' class="yourradio">
      <span></span>
      </label> 
<script>
$('.yourradio').on('click', function(){
 return false;
});