问题
I'm running a webpack server on virtual box with Ubuntu 15.10 using vagrant over mac OSX.
The webpack config is pretty clean:
var HtmlWebpackPlugin = require('html-webpack-plugin');
var path = require('path');
var webpack = require('webpack');
var MINIFY = process.env.MINIFY === true;
var FRONTEND_ROOT = './static'
var SRC_PATCH = FRONTEND_ROOT + '/scripts';
var BUILD_PATH = './dist';
module.exports = {
entry: SRC_PATCH + '/main.js',
devtool: 'source-map',
output: {
path: BUILD_PATH,
filename: 'bundle.js'
},
resolve: {
extensions: ['', '.js', '.jsx'],
modulesDirectories: [SRC_PATCH, 'node_modules']
},
plugins: [
new HtmlWebpackPlugin({
filename: 'index.html',
template: path.resolve(FRONTEND_ROOT, 'index-template.html'),
minify: MINIFY
})
],
module: {
loaders: [
{
test: /\.jsx|js$/,
exclude: /node_modules/,
loader: 'babel-loader'
}
]
},
eslint: {
configFile: './.eslintrc'
}
};
Webpack was run on VM by
vagrant@vagrant-ubuntu-wily-64:/vagrant$ webpack-dev-server --port 8080 --devtool eval --progress --colors --hot --content-base dist
And when I edit a file from OSX it doesn't reload, but if I edit the same file from VM it'll reload.
What is the problem? How can I fix it?
回答1:
I've solved my problem with vagrant rsync-auto
https://docs.vagrantup.com/v2/cli/rsync-auto.html
I'd added the line config.vm.synced_folder ".", "/vagrant", type: "rsync", rsync_auto: true, rsync_exclude: ".git/"
to my Vagrantfile
, and run vagrant rsync-auto
under a separate tab.
回答2:
This is answered under another question: https://stackoverflow.com/a/34937378/5114
If you add the --watch-poll
option it changes the way webpack looks for file changes.
webpack-dev-server --watch-poll --port 8080 --devtool eval --progress --colors --hot --content-base dist
This makes webpack poll for changes to the files every N milliseconds. Polling works in the Vagrant shared directories when the normal method doesn't because it doesn't look for mtime or other filesystem attributes, just reads the files on an interval. It's slower and uses more cpu/memory, so don't use polling unless you have to.
https://webpack.github.io/docs/cli.html#watch
回答3:
the first thing you need to see is if in the console where you're running the server, the recompiled process is happening or not. If' not the answer is in the SyncFolder line that @maxim-schepelin said above. If is recompiling and the web page is not reloading maybe the webPack solution.
Edit
Another reason for the folder sync not working the righ way could be this https://github.com/guard/listen/wiki/Increasing-the-amount-of-inotify-watchers
来源:https://stackoverflow.com/questions/33681004/webpack-dev-server-reload-doesnt-work-on-virtual-box