In WebpackDevMiddleware, allow configuration of ProjectPath (implements #262)

This commit is contained in:
SteveSandersonMS
2016-08-15 14:40:38 -07:00
parent 2a6465b27a
commit 0d0d25b032
2 changed files with 14 additions and 3 deletions

View File

@@ -35,15 +35,25 @@ namespace Microsoft.AspNetCore.Builder
"To enable ReactHotModuleReplacement, you must also enable HotModuleReplacement."); "To enable ReactHotModuleReplacement, you must also enable HotModuleReplacement.");
} }
string projectPath;
if (options.ProjectPath == null)
{
var hostEnv = (IHostingEnvironment)appBuilder.ApplicationServices.GetService(typeof(IHostingEnvironment));
projectPath = hostEnv.ContentRootPath;
}
else
{
projectPath = options.ProjectPath;
}
// Unlike other consumers of NodeServices, WebpackDevMiddleware dosen't share Node instances, nor does it // Unlike other consumers of NodeServices, WebpackDevMiddleware dosen't share Node instances, nor does it
// use your DI configuration. It's important for WebpackDevMiddleware to have its own private Node instance // use your DI configuration. It's important for WebpackDevMiddleware to have its own private Node instance
// because it must *not* restart when files change (if it did, you'd lose all the benefits of Webpack // because it must *not* restart when files change (if it did, you'd lose all the benefits of Webpack
// middleware). And since this is a dev-time-only feature, it doesn't matter if the default transport isn't // middleware). And since this is a dev-time-only feature, it doesn't matter if the default transport isn't
// as fast as some theoretical future alternative. // as fast as some theoretical future alternative.
var hostEnv = (IHostingEnvironment)appBuilder.ApplicationServices.GetService(typeof(IHostingEnvironment));
var nodeServices = Configuration.CreateNodeServices(new NodeServicesOptions var nodeServices = Configuration.CreateNodeServices(new NodeServicesOptions
{ {
ProjectPath = hostEnv.ContentRootPath, ProjectPath = projectPath,
WatchFileExtensions = new string[] { } // Don't watch anything WatchFileExtensions = new string[] { } // Don't watch anything
}); });
@@ -55,7 +65,7 @@ namespace Microsoft.AspNetCore.Builder
// Tell Node to start the server hosting webpack-dev-middleware // Tell Node to start the server hosting webpack-dev-middleware
var devServerOptions = new var devServerOptions = new
{ {
webpackConfigPath = Path.Combine(hostEnv.ContentRootPath, options.ConfigFile ?? DefaultConfigFile), webpackConfigPath = Path.Combine(projectPath, options.ConfigFile ?? DefaultConfigFile),
suppliedOptions = options suppliedOptions = options
}; };
var devServerInfo = var devServerInfo =

View File

@@ -6,5 +6,6 @@ namespace Microsoft.AspNetCore.SpaServices.Webpack
public int HotModuleReplacementServerPort { get; set; } public int HotModuleReplacementServerPort { get; set; }
public bool ReactHotModuleReplacement { get; set; } public bool ReactHotModuleReplacement { get; set; }
public string ConfigFile { get; set; } public string ConfigFile { get; set; }
public string ProjectPath { get; set; }
} }
} }