Webpack 开发服务器重新加载在虚拟机上不起作用 [英] Webpack dev server reload doesn't work on virtual box

查看:32
本文介绍了Webpack 开发服务器重新加载在虚拟机上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Ubuntu 15.10 的虚拟机上使用 vagrant 在 mac OSX 上运行 webpack 服务器.

I'm running a webpack server on virtual box with Ubuntu 15.10 using vagrant over mac OSX.

webpack 配置非常干净:

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 是在 VM 上运行的

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

当我从 OSX 编辑文件时,它不会重新加载,但如果我从 VM 编辑同一个文件,它会重新加载.

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?

推荐答案

我用 vagrant rsync-auto 解决了我的问题https://docs.vagrantup.com/v2/cli/rsync-auto.html

I've solved my problem with vagrant rsync-auto https://docs.vagrantup.com/v2/cli/rsync-auto.html

我已将 config.vm.synced_folder ".", "/vagrant", type: "rsync", rsync_auto: true, rsync_exclude: ".git/" 添加到我的 Vagrantfile,并在单独的选项卡下运行 vagrant rsync-auto.

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.

这篇关于Webpack 开发服务器重新加载在虚拟机上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆