コード例 #1
0
ファイル: Webpack.cs プロジェクト: mvarblow/aspnet-webpack
		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;
		}
コード例 #2
0
		/// <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;
		}
コード例 #3
0
 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;
 }
コード例 #4
0
		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>();
		}
コード例 #5
0
        /// <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);
        }
コード例 #6
0
ファイル: Webpack.cs プロジェクト: rongguoxu/aspnet-webpack
        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);
        }