0

webpack-hot-middlewareの問題にぶつかりました。複数のブラウザまたはタブのインスタンス(クロムとFF)を開くと、各ビジュアルアクションがトリガーされたときに表示されます。
たとえば、1つのタブでスクロールすると、別のタブでスクロールします。
誰でもこの現象が発生しましたか? のWebPACKのこの私の設定:webpack複数のタブ/ブラウザを使用すると、すべてのタブインスタンスでホットミドルウェアが更新される

import webpack from 'webpack'; 
import HtmlWebpackPlugin from 'html-webpack-plugin'; 
import autoprefixer from 'autoprefixer'; 
import path from 'path'; 

export default { 
    resolve: { 
    extensions: ['*', '.js', '.jsx', '.json'] 
    }, 
    devtool: 'eval-source-map', // more info:https://webpack.github.io/docs/build-performance.html#sourcemaps and https://webpack.github.io/docs/configuration.html#devtool 
    entry: [ 
    // must be first entry to properly set public path 
    './src/webpack-public-path', 
    'webpack-hot-middleware/client?reload=true', 
    path.resolve(__dirname, 'src/index.js') // Defining path seems necessary for this to work consistently on Windows machines. 
    ], 
    target: 'web', // necessary per https://webpack.github.io/docs/testing.html#compile-and-test 
    output: { 
    path: path.resolve(__dirname, 'dist'), // Note: Physical files are only output by the production build task `npm run build`. 
    publicPath: '/', 
    filename: 'bundle.js' 
    }, 

    plugins: [ 
    new webpack.DefinePlugin({ 
     'process.env.NODE_ENV': JSON.stringify('development'), // Tells React to build in either dev or prod modes. https://facebook.github.io/react/downloads.html (See bottom) 
     __DEV__: true 
    }), 
    new webpack.HotModuleReplacementPlugin(), 
    new webpack.NoEmitOnErrorsPlugin(), 
    new HtmlWebpackPlugin({  // Create HTML file that includes references to bundled CSS and JS. 
     template: 'src/index.html', 
     minify: { 
     removeComments: true, 
     collapseWhitespace: true 
     }, 
     inject: true 
    }), 
    new webpack.LoaderOptionsPlugin({ 
     minimize: false, 
     debug: true, 
     noInfo: true, // set to false to see a list of every file being bundled. 
     options: { 
     sassLoader: { 
      includePaths: [path.resolve(__dirname, 'src', 'scss')] 
     }, 
     context: '/', 
     postcss:() => [autoprefixer], 
     } 
    }) 
    ], 
    module: { 
    rules: [ 
     {test: /\.jsx?$/, exclude: /node_modules/, loaders: ['babel-loader']}, 
     {test: /\.eot(\?v=\d+.\d+.\d+)?$/, loader: 'file-loader'}, 
     {test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'url-loader?limit=10000&mimetype=application/font-woff'}, 
     {test: /\.[ot]tf(\?v=\d+.\d+.\d+)?$/, loader: 'url-loader?limit=10000&mimetype=application/octet-stream'}, 
     {test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: 'url-loader?limit=10000&mimetype=image/svg+xml'}, 
     {test: /\.(jpe?g|png|gif)$/i, loader: 'file-loader?name=[name].[ext]'}, 
     {test: /\.ico$/, loader: 'file-loader?name=[name].[ext]'}, 
     {test: /(\.css|\.scss|\.sass)$/, loaders: ['style-loader', 'css-loader?sourceMap', 'postcss-loader', 'sass-loader?sourceMap']} 
    ] 
    } 
}; 

私はもちろんのWebConfigを渡すの横のプラグインの特別なコンフィグありません:

// This file configures the development web server 
// which supports hot reloading and synchronized testing. 

// Require Browsersync along with webpack and middleware for it 
import browserSync from 'browser-sync'; 
// Required for react-router browserHistory 
// see https://github.com/BrowserSync/browser-sync/issues/204#issuecomment-102623643 
import historyApiFallback from 'connect-history-api-fallback'; 
import webpack from 'webpack'; 
import webpackDevMiddleware from 'webpack-dev-middleware'; 
import webpackHotMiddleware from 'webpack-hot-middleware'; 
import config from '../webpack.config.dev'; 

const bundler = webpack(config); 

// Run Browsersync and use middleware for Hot Module Replacement 
browserSync({ 
    port: 3000, 
    ui: { 
    port: 3001 
    }, 
    server: { 
    baseDir: 'src', 

    middleware: [ 
     historyApiFallback(), 

     webpackDevMiddleware(bundler, { 
     // Dev middleware can't access config, so we provide publicPath 
     publicPath: config.output.publicPath, 

     // These settings suppress noisy webpack output so only errors are displayed to the console. 
     noInfo: false, 
     quiet: false, 
     stats: { 
      assets: false, 
      colors: true, 
      version: false, 
      hash: false, 
      timings: false, 
      chunks: false, 
      chunkModules: false 
     }, 

     // for other settings see 
     // http://webpack.github.io/docs/webpack-dev-middleware.html 
     }), 

     // bundler should be the same as above 
     webpackHotMiddleware(bundler) 
    ] 
    }, 

    // no need to watch '*.js' here, webpack will take care of it for us, 
    // including full page reloads if HMR won't work 
    files: [ 
    'src/*.html' 
    ] 
}); 

答えて

1

をOK、私はこの行動の理由を発見し、そのに関連していませんwebpack-hot-middlewareはまったくありません。
これは実際にはbrowserSyncプラグインの原因です。
ドキュメントの一部を読んだあと、 がデフォルトでghostModeオプションがtrueに設定されていることがわかりました。

クリック、スクロール&任意のデバイスのフォーム入力は、他のすべてのデバイスに反映されます。

falseに設定すると無効にできます。 ghostMode: false

他人に役立つことを願っています。

関連する問題