Skip to content

Commit b7f7f3d

Browse files
authored
feat(templates): implement proper js module system for Boilerplate #11542 (#11543)
1 parent 28fe8bb commit b7f7f3d

File tree

11 files changed

+65
-40
lines changed

11 files changed

+65
-40
lines changed

src/Templates/Boilerplate/Bit.Boilerplate/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ custom.aprof
226226

227227
/src/**/App_Data/*
228228

229+
/src/Client/Boilerplate.Client.Core/Scripts/*.js
229230
/src/Client/Boilerplate.Client.Core/wwwroot/scripts/app*.js
230231
/src/Client/Boilerplate.Client.Maui/Platforms/Android/google-services.json
231232

src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Boilerplate.Client.Core.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@
6767

6868
<Target Name="BuildJavaScript" Inputs="@(TypeScriptFiles);tsconfig.json;package.json" Outputs="wwwroot\scripts\app.js">
6969
<Exec Command="node_modules/.bin/tsc" StandardOutputImportance="high" StandardErrorImportance="high" />
70-
<Exec Condition=" '$(Environment)' == 'Production' " Command="node_modules/.bin/esbuild wwwroot/scripts/app.js --minify --outfile=wwwroot/scripts/app.js --allow-overwrite" StandardOutputImportance="high" StandardErrorImportance="high" />
70+
<Exec Condition=" '$(Environment)' == 'Development' " Command="node_modules/.bin/esbuild Scripts/index.js --bundle --outfile=wwwroot/scripts/app.js" StandardOutputImportance="high" StandardErrorImportance="high" />
71+
<Exec Condition=" '$(Environment)' != 'Development' " Command="node_modules/.bin/esbuild Scripts/index.js --bundle --outfile=wwwroot/scripts/app.js --minify" StandardOutputImportance="high" StandardErrorImportance="high" />
7172
</Target>
7273

7374
<Target Name="BuildCssFiles">

src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Scripts/Ads.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
//+:cnd:noEmit
12
const gtag = (window as any).googletag = (window as any).googletag || { cmd: [] };
23

3-
class Ads {
4+
export class Ads {
45
private static rewardedSlot: any;
56
private static rewardPayload: any;
67
private static slotReadyEvent: any;
@@ -101,6 +102,4 @@ class Ads {
101102
})
102103
}
103104
}
104-
}
105-
106-
(window as any).Ads = Ads;
105+
}

src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Scripts/App.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
//+:cnd:noEmit
22

3-
interface DotNetObject {
4-
invokeMethod<T>(methodIdentifier: string, ...args: any[]): T;
5-
invokeMethodAsync<T>(methodIdentifier: string, ...args: any[]): Promise<T>;
6-
dispose(): void;
7-
}
8-
9-
class App {
3+
export class App {
104
// For additional details, see the JsBridge.cs file.
115
private static jsBridgeObj: DotNetObject;
126

@@ -95,4 +89,3 @@ class App {
9589
}
9690
}
9791

98-
(window as any).App = App;

src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Scripts/WebInteropApp.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1+
//+:cnd:noEmit
12
// Read Client.web/wwwroot/web-interop-app.html comments.
23

3-
declare class BitButil {
4-
static webAuthn: {
5-
getCredential: (options: unknown) => Promise<unknown>,
6-
createCredential: (options: unknown) => Promise<unknown>
7-
}
8-
};
9-
10-
class WebInteropApp {
4+
export class WebInteropApp {
115
private static autoClose = true;
126

137
public static async run() {
@@ -116,6 +110,4 @@ class WebInteropApp {
116110
credentials: 'omit'
117111
});
118112
}
119-
}
120-
121-
(window as any).WebInteropApp = WebInteropApp;
113+
}

src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Scripts/bswup.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//+:cnd:noEmit
22

3+
import { App } from './App';
4+
35
(function () {
46
const bswup = (window as any).BitBswup; // https://bitplatform.dev/bswup
57
if (!bswup) return;

src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Scripts/events.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//+:cnd:noEmit
22

3+
import { App } from './App';
4+
35
(function () {
46
window.addEventListener('load', handleLoad);
57
window.addEventListener('message', handleMessage);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//+:cnd:noEmit
2+
3+
import './bswup';
4+
import './theme';
5+
import './events';
6+
import { App } from './App';
7+
import { WebInteropApp } from './WebInteropApp';
8+
//#if (ads == true)
9+
import { Ads } from './Ads';
10+
//#endif
11+
12+
// Expose classes on window global
13+
(window as any).App = App;
14+
(window as any).WebInteropApp = WebInteropApp;
15+
//#if (ads == true)
16+
(window as any).Ads = Ads;
17+
//#endif

src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Scripts/theme.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,14 @@
11
//+:cnd:noEmit
22

3-
declare class BitTheme { static init(options: BitThemeOptions): void; };
4-
5-
interface BitThemeOptions {
6-
system?: boolean;
7-
persist?: boolean;
8-
theme?: string | null;
9-
default?: string | null;
10-
darkTheme?: string | null;
11-
lightTheme?: string | null;
12-
onChange?: onThemeChangeType;
13-
}
14-
15-
type onThemeChangeType = (newThemeName: string, oldThemeName: string) => void;
3+
// The following code gives you ideas on how to handle bit theme changes in your application.
164

175
(function () {
18-
BitTheme?.init({
6+
if (typeof BitTheme === 'undefined')
7+
return;
8+
BitTheme.init({
199
system: true,
2010
persist: true,
21-
onChange: (newTheme: string, oldTheme: string) => {
11+
onChange: (newTheme, oldTheme) => {
2212
document.body.classList.add('theme-' + newTheme);
2313
document.body.classList.remove('theme-' + oldTheme);
2414

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Blazor types:
2+
declare interface DotNetObject {
3+
invokeMethod<T>(methodIdentifier: string, ...args: any[]): T;
4+
invokeMethodAsync<T>(methodIdentifier: string, ...args: any[]): Promise<T>;
5+
dispose(): void;
6+
}
7+
8+
// Bit.Butil types:
9+
declare class BitButil {
10+
static webAuthn: {
11+
getCredential: (options: unknown) => Promise<unknown>,
12+
createCredential: (options: unknown) => Promise<unknown>
13+
}
14+
}
15+
16+
// Bit.BlazorUI types:
17+
declare class BitTheme { static init(options: BitThemeOptions): void; }
18+
19+
declare interface BitThemeOptions {
20+
system?: boolean;
21+
persist?: boolean;
22+
theme?: string | null;
23+
default?: string | null;
24+
darkTheme?: string | null;
25+
lightTheme?: string | null;
26+
onChange?: (newThemeName: string, oldThemeName: string) => void;
27+
}

0 commit comments

Comments
 (0)