我最近开始使用Webpack 2和开发服务器,它工作正常。一旦我添加了webpack dev服务器的选项,它就会做它应该做的事情,只在命令行中显示最少的反馈但停止实时刷新?以下是我为操作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
对于上下文,这是我的webpack配置:
{
"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"
}
}
这是我的package.json,脚本位于:
var task1 = GetNamesFromSource1Async(); // a database call, may throw an exception
var task2 = GetNamesFromSource2Async(); // a database call, may throw an exception
var total = new List<string>();
await Task.WhenAll(task1, taks2).ConfigureAwait(false);
我无法弄清楚为什么这个选项会淘汰实时重播?有任何见解赞赏!
答案 0 :(得分:1)
我发现实现我想要的最简单方法是将我的package.json中的启动脚本调整为:
"start": "webpack-dev-server --hot --inline"
然后在我的webpack配置中,我保留了最小统计数据选项,现在所有工作都按预期工作。