mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-26 03:27:30 +00:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user