File tree 1 file changed +32
-0
lines changed
src/React.Template/reactnet-webpack
1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ using System . Diagnostics ;
2
+ using System . Threading ;
3
+ using System . Threading . Tasks ;
1
4
using Microsoft . AspNetCore ;
2
5
using Microsoft . AspNetCore . Hosting ;
6
+ using Microsoft . Extensions . Hosting ;
7
+ using Microsoft . Extensions . DependencyInjection ;
8
+ using System ;
3
9
4
10
namespace React . Sample . Webpack . CoreMvc
5
11
{
@@ -13,6 +19,32 @@ public static void Main(string[] args)
13
19
public static IWebHost BuildWebHost ( string [ ] args ) =>
14
20
WebHost . CreateDefaultBuilder ( args )
15
21
. UseStartup < Startup > ( )
22
+ . ConfigureServices ( ( hostContext , service ) =>
23
+ {
24
+ service . AddHostedService < WebpackDevServer > ( ) ;
25
+ } )
16
26
. Build ( ) ;
27
+
28
+ private class WebpackDevServer : BackgroundService
29
+ {
30
+ protected override Task ExecuteAsync ( CancellationToken token )
31
+ {
32
+ if ( Environment . OSVersion . Platform == PlatformID . Win32NT )
33
+ {
34
+ var devServer = Process . Start ( new ProcessStartInfo
35
+ {
36
+ Arguments = "/c npm i && npm run build -- --watch" ,
37
+ RedirectStandardError = false ,
38
+ RedirectStandardInput = false ,
39
+ RedirectStandardOutput = false ,
40
+ FileName = "cmd.exe"
41
+ } ) ;
42
+
43
+ token . Register ( ( ) => devServer ? . Kill ( true ) ) ;
44
+ }
45
+
46
+ return Task . Delay ( Timeout . Infinite , token ) ;
47
+ }
48
+ }
17
49
}
18
50
}
You can’t perform that action at this time.
0 commit comments