WEBPACK DEV SERVER 不是 运行 即使 webpack 正确生成 bundle.js

WEBPACK DEV SERVER is not running even though webpack properly generates bundle.js

我尝试在 Gulp 任务中 运行 webpack-dev-server,但即使 webpack 正确生成 bundle.jswebpack-dev-server 也不是 运行宁。

当我调用'http://[IP计算机地址]:8080'时,提示'无法访问此站点'。

以下是 Gulp 任务:

import webpack from 'webpack';
import config from './webpack.config';
import WebpackDevServer from 'webpack-dev-server';

...

gulp.task('serve', () => {
  const compiler = webpack(config);
  const devServer = new WebpackDevServer(compiler, {
    quiet: false
  }).listen(8080,  'localhost', (err) => {
    if(err) {
      console.log(err);
    }
  });
});

webpack.config.js是:

const BUILD_DIR = path.resolve(__dirname, 'dist/');
const APP_DIR = path.resolve(__dirname, 'client');

export default {
    entry: APP_DIR + '/index.jsx',
    output: {
        path: BUILD_DIR,
        filename: 'bundle.js'
    }
};

结果我得到以下输出:

[10:29:52] Requiring external module babel-register
[10:29:55] Using gulpfile /Volumes/MACDATA/Current_Work/ES6Twitter/project/Hooter/gulpfile.babel.js
[10:29:55] Starting 'serve'...
[10:29:55] Finished 'serve' after 50 ms
Hash: 503283de8850d977b4ec
Version: webpack 1.13.2
Time: 53ms
    Asset     Size  Chunks             Chunk Names
bundle.js  1.42 kB       0  [emitted]  main
chunk    {0} bundle.js (main) 29 bytes [rendered]
    [0] ./client/index.jsx 29 bytes {0} [built]
webpack: bundle is now VALID.

我该如何解决这个错误?

您正在指定 localhost,但您想从外部计算机连接。在这种情况下,您需要将 localhost 更改为 0.0.0.0。这使得开发服务器可以在外部机器上访问。