diff --git a/src/Microsoft.AspNetCore.SpaServices/Webpack/WebpackDevMiddleware.cs b/src/Microsoft.AspNetCore.SpaServices/Webpack/WebpackDevMiddleware.cs index a9398d7..89d6950 100644 --- a/src/Microsoft.AspNetCore.SpaServices/Webpack/WebpackDevMiddleware.cs +++ b/src/Microsoft.AspNetCore.SpaServices/Webpack/WebpackDevMiddleware.cs @@ -35,15 +35,25 @@ namespace Microsoft.AspNetCore.Builder "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 // 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 // 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. - var hostEnv = (IHostingEnvironment)appBuilder.ApplicationServices.GetService(typeof(IHostingEnvironment)); var nodeServices = Configuration.CreateNodeServices(new NodeServicesOptions { - ProjectPath = hostEnv.ContentRootPath, + ProjectPath = projectPath, 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 var devServerOptions = new { - webpackConfigPath = Path.Combine(hostEnv.ContentRootPath, options.ConfigFile ?? DefaultConfigFile), + webpackConfigPath = Path.Combine(projectPath, options.ConfigFile ?? DefaultConfigFile), suppliedOptions = options }; var devServerInfo = diff --git a/src/Microsoft.AspNetCore.SpaServices/Webpack/WebpackDevMiddlewareOptions.cs b/src/Microsoft.AspNetCore.SpaServices/Webpack/WebpackDevMiddlewareOptions.cs index fcdde44..ebfe36d 100644 --- a/src/Microsoft.AspNetCore.SpaServices/Webpack/WebpackDevMiddlewareOptions.cs +++ b/src/Microsoft.AspNetCore.SpaServices/Webpack/WebpackDevMiddlewareOptions.cs @@ -6,5 +6,6 @@ namespace Microsoft.AspNetCore.SpaServices.Webpack public int HotModuleReplacementServerPort { get; set; } public bool ReactHotModuleReplacement { get; set; } public string ConfigFile { get; set; } + public string ProjectPath { get; set; } } } \ No newline at end of file