简体   繁体   English

fluxible run dev触发两次,如何配置webpack和nodemon的dev启动脚本?

[英]fluxible run dev is firing twice, how should I configure the dev start script with webpack and nodemon?

I'm returning to an old fluxible project I started a while back and when I use npm run dev it seems to be starting twice and is throwing an error. 我回到了一个前一段时间开始的易变项目,当我使用npm run dev它似乎启动了两次,并引发了错误。 It used to work - what is the configuration that's causing this error? 它曾经可以工作-导致此错误的配置是什么? Is the standard fluxible configuration supposed to be running two web servers one on port 3000 and one on 3001? 标准的易变配置是否应该运行两台Web服务器,一台在端口3000上,一台在3001上?

> node webpack-dev-server.js & PORT=3001 nodemon start.js -e js,jsx

[nodemon] 1.8.1
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node start.js`
Webpack Dev Server listening on port 3000
[nodemon] 1.8.1
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node start.js`
using redis session
Application listening on port 3001
events.js:141
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE :::3001

I noticed that in the webpack-dev-server.js it is also calling start.js as well. 我注意到在webpack-dev-server.js中,它也正在调用start.js。

var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var config = require('./webpack.config');
var shell = require('shelljs');

new WebpackDevServer(webpack(config), {
    publicPath: config.output.publicPath,
    hot: true,
    historyApiFallback: true,
    //quiet: true,
    proxy: {
        '*': { target: 'http://localhost:3001' }
    }
}).listen(3000, function () {
    shell.env.PORT = shell.env.PORT || 3001;
    shell.exec('"./node_modules/.bin/nodemon" start.js -e js,jsx', function () {});
    console.log('Webpack Dev Server listening on port 3000');
});

maybe that shell.exec call to start.js is redundant? 也许对start.js的shell.exec调用是多余的?

I think your intuition is correct. 我认为你的直觉是正确的。 Try running this command: 尝试运行以下命令:

node webpack-dev-server.js

Whats happening is, the node program (webpack-dev-server.js) starts a webpack-dev-server on port 3000, and then starts a nodemon service on port 3001. The command you are running in the terminal is using a ampersand, so it's also starting a third server in parallel. 发生的情况是,节点程序(webpack-dev-server.js)在端口3000上启动了webpack-dev-server,然后在端口3001上启动了nodemon服务。您在终端中运行的命令使用&符号,因此它也同时启动了第三台服务器。 This server is also running on port 3001. 该服务器也在端口3001上运行。

I suspect the error being raised is caused by the port already being used by the parallel process. 我怀疑引发的错误是由并行进程已经使用的端口引起的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM