我尝试在Gulp任务中运行webpack-dev-server
,但即使webpack正确生成bundle.js
,webpack-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.
如何解决此错误?
答案 0 :(得分:1)
您指定localhost
,但您想从外部计算机连接。在这种情况下,您需要将localhost
更改为0.0.0.0
。这使得dev服务器可以在外部机器上访问。