我正在尝试运行webpack -w但它没有按预期连续运行。之前它曾用于重建我的代码中的每个保存。但现在它已停止工作,因为我必须每次运行webpack -w才能进行更改。
如果我需要提供任何其他信息,请告诉我。
//package.json
{
"name": "react",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "webpack-dev-server --color --inline --content-base public/ --history-api-fallback"
},
"repository": {
"type": "git",
"url": "*************"
},
"author": "",
"license": "ISC",
"homepage": "*********************",
"dependencies": {
"flux": "^2.1.1",
"jquery": "^3.0.0",
"material-ui": "^0.15.0",
"react": "^15.1.0",
"react-bootstrap-table": "^2.3.5",
"react-dom": "^15.1.0",
"react-mdl": "^1.5.4",
"react-router": "^2.4.1",
"react-tap-event-plugin": "^1.0.0"
},
"devDependencies": {
"babel-core": "^6.9.1",
"babel-loader": "^6.2.4",
"babel-preset-es2015": "^6.9.0",
"babel-preset-react": "^6.5.0",
"http-server": "^0.9.0",
"path": "^0.12.7",
"react-router": "^2.4.1",
"react-sidenav": "^1.0.4",
"webpack": "^1.13.1",
"webpack-dev-server": "^1.14.1"
}
}
// webpack.config.js
var debug = process.env.NODE_ENV !== "production";
var webpack = require('webpack');
module.exports = {
context: __dirname,
devtool: "inline-sourcemap",
entry: "./app/index.js",
output: {
path: __dirname + "/public/",
filename: "bundle.js"
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader?presets[]=es2015&presets[]=react'
}
]
},
plugins: debug ? [] : [
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false }),
],
};
这是我运行“webpack -w”
时会发生什么$ webpack -w
Hash: 5f80fac0cde2c497f037
Version: webpack 1.13.1
Time: 4146ms
Asset Size Chunks Chunk Names
./public/bundle.js 3.03 MB 0 [emitted] main
+ 653 hidden modules
$
它应该继续运行我的服务器并查找发生的更改。
答案 0 :(得分:0)
如果我理解你的问题,你的问题在于webpack热重装
为此,您需要指定webpack在热重新加载时查找的位置。 如果我没错,我在配置文件中的条目对象中没有看到任何内存位置。
另外,如果可能,请发布server.js的相关部分。我们回答你的问题会很有帮助。
尝试添加此内容:
entry: [
'webpack-dev-server/client?http://0.0.0.0:3000', // WebpackDevServer host and port
'webpack/hot/only-dev-server', // "only" prevents reload on syntax errors
'./app/index.js' // Your appʼs entry point
]
答案 1 :(得分:0)
问题是我的系统中没有太多可用的观察者。如果此值太低,Webpack中的文件观察程序将无法识别更改。
cat /proc/sys/fs/inotify/max_user_watches
Ubuntu用户(可能还有其他用户):
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p.
这解决了我的问题。
以下是链接:not-enough-watchers