@@ -9,12 +9,12 @@ namespace MvcReact;
9
9
10
10
public static class ServiceCollectionExtensions
11
11
{
12
- public static IServiceCollection AddMvcReact ( this IServiceCollection services )
12
+ public static IServiceCollection AddCraServices ( this IServiceCollection services )
13
13
{
14
- return services . AddMvcReact ( _ => { } ) ;
14
+ return services . AddCraServices ( _ => { } ) ;
15
15
}
16
16
17
- public static IServiceCollection AddMvcReact ( this IServiceCollection services , Action < MvcReactOptions > configureOptions )
17
+ public static IServiceCollection AddCraServices ( this IServiceCollection services , Action < MvcReactOptions > configureOptions )
18
18
{
19
19
Action < MvcReactOptions > optionBuilder = options =>
20
20
{
@@ -24,14 +24,55 @@ public static IServiceCollection AddMvcReact(this IServiceCollection services, A
24
24
options . IndexHtmlPath = "ClientApp/build/index.html" ;
25
25
options . StaticAssetBasePath = "/static" ;
26
26
options . StaticAssetHeaderCacheMaxAgeDays = 365 ;
27
- options . DevServerBundlePath = "/static/js/bundle.js" ;
27
+ options . CraDevServerBundlePath = "/static/js/bundle.js" ;
28
28
options . DevServerStartScript = "start" ;
29
+ options . DevServerType = DevServerType . CRA ;
30
+ options . DevServerPort = 3000 ;
29
31
options . TagHelperCacheMinutes = 30 ;
30
32
options . ExcludeHmrPathsRegex = "^(?!ws|.*?hot-update.js(on)?).*$" ;
31
33
32
34
// allow for custom config...
33
35
configureOptions ( options ) ;
34
36
} ;
37
+
38
+ AddReactMvcServices ( services , optionBuilder ) ;
39
+
40
+ return services ;
41
+ }
42
+
43
+ public static IServiceCollection AddViteServices ( this IServiceCollection services )
44
+ {
45
+ return services . AddViteServices ( _ => { } ) ;
46
+ }
47
+
48
+ public static IServiceCollection AddViteServices ( this IServiceCollection services , Action < MvcReactOptions > configureOptions )
49
+ {
50
+ Action < MvcReactOptions > optionBuilder = options =>
51
+ {
52
+ // default config happens here
53
+ options . SourcePath = "ClientApp" ;
54
+ options . BuildPath = "ClientApp/build" ;
55
+ options . IndexHtmlPath = "ClientApp/build/index.html" ;
56
+ options . StaticAssetBasePath = "/static" ;
57
+ options . StaticAssetHeaderCacheMaxAgeDays = 365 ;
58
+ options . DevServerStartScript = "start" ;
59
+ options . DevServerType = DevServerType . Vite ;
60
+ options . DevServerPort = 5173 ;
61
+ options . ViteDevServerEntry = "/index.tsx" ;
62
+ options . TagHelperCacheMinutes = 30 ;
63
+
64
+
65
+ // allow for custom config...
66
+ configureOptions ( options ) ;
67
+ } ;
68
+
69
+ AddReactMvcServices ( services , optionBuilder ) ;
70
+
71
+ return services ;
72
+ }
73
+
74
+ private static void AddReactMvcServices ( IServiceCollection services , Action < MvcReactOptions > optionBuilder )
75
+ {
35
76
services . Configure ( optionBuilder ) ;
36
77
37
78
// not sure if there is a better way to get at the options here
@@ -46,7 +87,6 @@ public static IServiceCollection AddMvcReact(this IServiceCollection services, A
46
87
services . AddScoped < IInternalFileProvider > ( _ => new InternalFileProvider ( Directory . GetCurrentDirectory ( ) ) ) ; // lgtm [cs/local-not-disposed]
47
88
services . AddTransient < ITagHelper , ReactScriptsTagHelper > ( ) ;
48
89
services . AddTransient < ITagHelper , ReactStylesTagHelper > ( ) ;
49
- return services ;
50
90
}
51
91
52
92
}
0 commit comments