public WebPackMiddlewareOptions Execute(string configFile, string outputFileName, WebpackDevServerOptions devServerOptions) { var enableHotLoading = devServerOptions != null; var toolToExecute = enableHotLoading ? webpackDevServer : webpack; var logger = _loggerFactory.CreateLogger(toolToExecute); logger.LogInformation($"Verifying required tools are installed"); EnsuereNodeModluesInstalled(enableHotLoading, logger); logger.LogInformation($"All node modules are properly installed"); logger.LogInformation($"{toolToExecute} Execution started"); var arguments = $"--config {configFile}"; logger.LogInformation($"{toolToExecute} is called with these arguments: {arguments}"); Process process = new Process(); process.StartInfo = new ProcessStartInfo() { FileName = GetNodeExecutable(toolToExecute), Arguments = arguments, UseShellExecute = false }; process.Start(); logger.LogInformation($"{toolToExecute} started successfully"); var middleWareOptions = new WebPackMiddlewareOptions { OutputFileName = outputFileName, EnableHotLoading = enableHotLoading }; if (enableHotLoading) { middleWareOptions.Host = devServerOptions.Host; middleWareOptions.Port = devServerOptions.Port; } return middleWareOptions; }
/// <summary> /// Adds webpack functionality to the application. It should be used only in development environment. /// This method is used when we need to enable hot loading. /// The <paramref name="outputFileName"/> and <paramref name="devServerOptions"/> are required for the underlying middleware to add the appropriate script tag /// </summary> /// <param name="configFile">The path to the external configuration file e.g. webpack/webpack.development.js</param> /// <param name="outputFileName"> /// The file name of the output bundle /// This value must be the same as the one in external configuration file output section /// output: { /// filename: 'bundle.js', /// }, /// </param> /// <param name="devServerOptions"> /// The development server configuration options /// These values should be the same as the ones in external configuration file devserver section /// devServer: { /// host: "0.0.0.0", /// port: "3000", /// }, /// </param> public static IApplicationBuilder UseWebpack( this IApplicationBuilder app, string configFile, string outputFileName, WebpackDevServerOptions devServerOptions) { var webpack = app.ApplicationServices.GetService<IWebpack>(); var options = webpack.Execute(configFile, outputFileName, devServerOptions); app.UseMiddleware<WebpackMiddleware>(options); return app; }
public WebpackOptions(string entryPoint = "app/index.js", string outputFileName = "bundle.js", bool handleStyles = true) { EntryPoint = entryPoint; DevToolType = DevToolType.SourceMap; EnableES2015 = true; HandleStyles = handleStyles; DevServerOptions = new WebpackDevServerOptions(); StylesTypes = new List <StylesType>(); StaticFileTypes = new List <StaticFileType>(); OutputFileName = outputFileName; }
public WebpackOptions( string entryPoint = "app/index.js", string outputFileName = "bundle.js", bool handleStyles = true) { EntryPoint = entryPoint; OutputFileName = outputFileName; HandleStyles = handleStyles; DevServerOptions = new WebpackDevServerOptions(); StylesTypes = new List<StylesType>(); StaticFileTypes = new List<StaticFileType>(); }
/// <summary> /// Adds webpack functionality to the application. It should be used only in development environment. /// This method is used when we need to enable hot loading. /// The <paramref name="outputFileName"/> and <paramref name="devServerOptions"/> are required for the underlying middleware to add the appropriate script tag /// </summary> /// <param name="configFile">The path to the external configuration file e.g. webpack/webpack.development.js</param> /// <param name="outputFileName"> /// The file name of the output bundle /// This value must be the same as the one in external configuration file output section /// output: { /// filename: 'bundle.js', /// }, /// </param> /// <param name="devServerOptions"> /// The development server configuration options /// These values should be the same as the ones in external configuration file devserver section /// devServer: { /// host: "0.0.0.0", /// port: "3000", /// }, /// </param> public static IApplicationBuilder UseWebpack( this IApplicationBuilder app, string configFile, string outputFileName, WebpackDevServerOptions devServerOptions) { var webpack = app.ApplicationServices.GetService <IWebpack>(); var options = webpack.Execute(configFile, outputFileName, devServerOptions); app.UseMiddleware <WebpackMiddleware>(options); return(app); }
public WebPackMiddlewareOptions Execute(string configFile, string outputFileName, WebpackDevServerOptions devServerOptions) { var enableHotLoading = devServerOptions != null; var toolToExecute = enableHotLoading ? webpackDevServer : webpack; var logger = _loggerFactory.CreateLogger(toolToExecute); logger.LogInformation($"Verifying required tools are installed"); EnsuereNodeModluesInstalled(enableHotLoading, logger); logger.LogInformation($"All node modules are properly installed"); logger.LogInformation($"{toolToExecute} Execution started"); var arguments = $"--config {configFile}"; logger.LogInformation($"{toolToExecute} is called with these arguments: {arguments}"); Process process = new Process(); process.StartInfo = new ProcessStartInfo() { FileName = GetWebpackToolToExeceute(toolToExecute), Arguments = arguments, UseShellExecute = false }; process.Start(); logger.LogInformation($"{toolToExecute} started successfully"); var middleWareOptions = new WebPackMiddlewareOptions { OutputFileName = outputFileName, EnableHotLoading = enableHotLoading }; if (enableHotLoading) { middleWareOptions.Host = devServerOptions.Host; middleWareOptions.Port = devServerOptions.Port; } return(middleWareOptions); }