Ejemplo n.º 1
0
        public WebPackMiddlewareOptions Execute(string configFile, WebpackOptions options)
        {
            var enableHotLoading = options.DevServerOptions != null;
            var toolToExecute    = enableHotLoading ? WEBPACK_DEV_SERVER : 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 hotModuleReplcementTag = options.EnableHotModuleReplacement && enableHotLoading ? "--hot" : string.Empty;
            var arguments = $"--config {configFile} {hotModuleReplcementTag}";

            logger.LogInformation($"{toolToExecute} is called with these arguments: {arguments}");
            new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName        = GetWebpackToolToExeceute(toolToExecute),
                    Arguments       = arguments,
                    UseShellExecute = false
                }
            }.Start();
            logger.LogInformation($"{toolToExecute} started successfully");

            var middleWareOptions = new WebPackMiddlewareOptions
            {
                OutputFileNames  = options.GetBundlesList(),
                EnableHotLoading = enableHotLoading
            };

            if (!enableHotLoading)
            {
                return(middleWareOptions);
            }

            middleWareOptions.Host = options.DevServerOptions.Host;
            middleWareOptions.Port = options.DevServerOptions.Port;
            return(middleWareOptions);
        }
Ejemplo n.º 2
0
        public WebPackMiddlewareOptions Execute(WebpackOptions options)
        {
            var toolToExecute = options.EnableHotLoading ? WEBPACK_DEV_SERVER : WEBPACK;
            var logger        = _loggerFactory.CreateLogger(toolToExecute);

            logger.LogInformation($"Verifying required tools are installed");
            EnsuereNodeModluesInstalled(options.EnableHotLoading, logger);
            logger.LogInformation($"All node modules are properly installed");

            var includeDefaultConfigFile = CreateWebpackConfigurationFile(options);

            logger.LogInformation($"{toolToExecute} Execution started");
            try {
                var arguments = ArgumentsHelper.GetWebpackArguments(_webRootPath, options, includeDefaultConfigFile);
                logger.LogInformation($"{toolToExecute} is called with these arguments: {arguments}");
                new Process
                {
                    StartInfo = new ProcessStartInfo()
                    {
                        FileName        = GetWebpackToolToExeceute(toolToExecute),
                        Arguments       = arguments,
                        UseShellExecute = false
                    }
                }.Start();
                logger.LogInformation($"{toolToExecute} started successfully");

                return(new WebPackMiddlewareOptions {
                    EnableHotLoading = options.EnableHotLoading,
                    OutputFileNames = options.GetBundlesList(),
                    Host = options.DevServerOptions.Host,
                    Port = options.DevServerOptions.Port
                });
            }
            catch (Win32Exception) {
                throw new InvalidProgramException("IIS Express is not supported by Asp.net Webpack. Please use Kestrel instead");
            }
        }