2017-02-24 65 views
0

我最近開始使用Webpack 2與開發工作正常的服務器。一旦我添加了webpack dev服務器的選項,它就會按照它應該做的事情做,只在命令行中顯示最少的反饋,但會停止實時刷新?這是我加入操縱的WebPack的反饋選項:Webpack 2 devServer選項會導致實時重新加載?

devServer: { 
    stats: 'minimal' 
}, 

和上下文,這裏是我的WebPack配置:

import webpack from 'webpack' 
import path from 'path' 
import ExtractTextPlugin from 'extract-text-webpack-plugin' 

const nodeModules  = path.resolve(__dirname, 'node_modules') 

const config = { 

    entry: './src/js/index.js', 
    output: { 
     path: path.join(__dirname, "site/assets"), 
     filename: 'index.js', 
     publicPath: '/site/assets' 
    }, 

    devServer: { 
     stats: 'minimal' 
    }, 

    module: { 
     rules: [ 
      { 
       test  : /\.js$/, 
       loader : 'babel-loader', 
       exclude : [nodeModules] 
      }, 
      { 
       test: /\.css$/, 
       loader: "style-loader!css-loader" 
      }, 

      { 
       test  : /\.scss$/, 
       use  : ExtractTextPlugin.extract({ 
        fallback: 'style-loader', 
        use: ['css-loader', 'sass-loader'] 
       }), 
       exclude : [nodeModules] 
      }, 
      { 
       test  : /\.(png|jpg)$/, 
       loader : 'url-loader' 
      } 
     ] 
    }, 

    plugins: [ 
     new ExtractTextPlugin('main.css') 
    ] 
}; 

export default config 

這裏是我的package.json與腳本:

{ 
    "name": "webpack-demo", 
    "version": "1.0.0", 
    "description": "", 
    "main": "index.js", 
    "scripts": { 
    "watch": "webpack --progress --colors --watch", 
    "build": "webpack --progress --colors", 
    "deploy": "NODE_ENV=production webpack -p --progress --colors", 
    "start": "webpack-dev-server" 
    }, 
    "keywords": [], 
    "author": "", 
    "license": "ISC", 
    "devDependencies": { 
    "webpack": "^2.2.1" 
    }, 
    "dependencies": { 
    "babel-core": "^6.23.1", 
    "babel-loader": "^6.3.2", 
    "babel-polyfill": "^6.23.0", 
    "babel-preset-es2015": "^6.22.0", 
    "babel-preset-stage-0": "^6.22.0", 
    "base-64": "^0.1.0", 
    "bourbon": "^4.3.2", 
    "css-loader": "^0.26.1", 
    "extract-text-webpack-plugin": "^2.0.0-beta", 
    "file-loader": "^0.10.0", 
    "fractions-2": "^2.1.7", 
    "json-loader": "^0.5.4", 
    "lodash": "^4.17.4", 
    "node-sass": "^4.5.0", 
    "sass-loader": "^6.0.2", 
    "style-loader": "^0.13.1", 
    "url-loader": "^0.5.7", 
    "webpack-dev-server": "^2.4.1" 
    } 
} 

我弄不明白爲什麼這個選項會淘汰現場重裝?任何洞察讚賞!

回答

1

我發現,實現最簡單的方法是什麼,我想在我的package.json來適應我的啓動腳本這樣:

"start": "webpack-dev-server --hot --inline" 

然後在我的WebPack配置我不停的最小統計選項現在一切按預期工作。

相關問題