public ReactBundleTagHelper(ISpaStaticFileProvider spaFiles) { var provider = spaFiles.FileProvider ?? throw new ArgumentNullException($"The SPA directory does not exist. Did you run 'npm run build' first?"); var statsFile = provider.GetFileInfo("stats.json"); if (!statsFile.Exists) { throw new InvalidOperationException("stats.json does not exist at the root of the spa static files directory. Is the webpack-stats-plugin plugin properly configured?"); } using var reader = new StreamReader(statsFile.CreateReadStream()); var statsFileContents = reader.ReadToEnd(); _webpackStats = (WebpackStats)JsonSerializer.Deserialize(statsFileContents, typeof(WebpackStats), new JsonSerializerOptions { PropertyNameCaseInsensitive = true } ); // flatten the chunks to one list of Assets _allAssets = _webpackStats.AssetsByChunkName .SelectMany(a => a.Value.Select(a2 => new Asset(a.Key, a2))) .ToList(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ISpaStaticFileProvider spa) { app.Use(async(context, next) => { context.Items.Add("ServiceUser", new { }); context.Items.Add("Lang", "tr-TR"); await next.Invoke(); }); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions { HotModuleReplacement = true, ReactHotModuleReplacement = true }); app.UseHsts(); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseSpaStaticFiles(); app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapRazorPages(); }); }