WebpackDevMiddleware should run in a separate Node instance that doesn't restart when files change (otherwise there's no point in running it at all)

This commit is contained in:
SteveSandersonMS
2016-02-09 17:26:04 -08:00
parent 6c903f33ae
commit 2e9a43d1dc
6 changed files with 76 additions and 24 deletions

View File

@@ -2,9 +2,12 @@
// but simplifies things for the consumer of this module.
var http = require('http');
var path = require('path');
var requestedPortOrZero = parseInt(process.argv[2]) || 0; // 0 means 'let the OS decide'
var parsedArgs = parseArgs(process.argv);
var requestedPortOrZero = parsedArgs.port || 0; // 0 means 'let the OS decide'
autoQuitOnFileChange(process.cwd(), ['.js', '.jsx', '.ts', '.tsx', '.json', '.html']);
if (parsedArgs.watch) {
autoQuitOnFileChange(process.cwd(), parsedArgs.watch.split(','));
}
var server = http.createServer(function(req, res) {
readRequestBodyAsJson(req, function(bodyJson) {
@@ -75,3 +78,22 @@ function autoQuitOnFileChange(rootDir, extensions) {
}
});
}
function parseArgs(args) {
// Very simplistic parsing which is sufficient for the cases needed. We don't want to bring in any external
// dependencies (such as an args-parsing library) to this file.
var result = {};
var currentKey = null;
args.forEach(function(arg) {
if (arg.indexOf('--') === 0) {
var argName = arg.substring(2);
result[argName] = undefined;
currentKey = argName;
} else if (currentKey) {
result[currentKey] = arg;
currentKey = null;
}
});
return result;
}