Make dotnet.js and dotnet.boot.js import more EASY IN WEB WORKER
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 276
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Is your feature request related to a problem? Please describe the problem.
**Currently the **#[.{fingerprint}]** replacing only works for index.html. It makes dotnet.js and dotnet.boot.js import very difficult in webworker and need to write a lot urgly codes.**
### Describe the solution you'd like
**If the build or publish flow can replace all import path for all js or html files, it would be great for our developers!**
### Additional context
**Workarround:**
[QRGenerator.razor.js](https://github.com/user-attachments/files/26331934/QRGenerator.razor.js)
[QRGeneratorClient.razor.js](https://github.com/user-attachments/files/26331935/QRGeneratorClient.razor.js)
**Use post message to init:**
```
let dotnetJsUrl = '../_framework/dotnet.js';
let dotnetBootJsUrl = '../_framework/dotnet.boot.js';
await sendRequestToWorker({ command: 'init', dotnetJsUrl: import.meta.resolve?.(dotnetJsUrl) ?? dotnetJsUrl, dotnetBootJsUrl: import.meta.resolve?.(dotnetBootJsUrl) ?? dotnetBootJsUrl });
```
```
switch (command) {
case 'init':
try {
let dotnetJsUrl = e.data.dotnetJsUrl;
let dotnetBootJsUrl = e.data.dotnetBootJsUrl;
console.log(`Initializing worker with dotnet.js: ${dotnetJsUrl}, dotnet.boot.js: ${dotnetBootJsUrl}`, );
if (!dotnetJsUrl) {
console.warn('dotnetJsUrl not provided, using default path');
dotnetJsUrl = '../_framework/dotnet.js';
}
const { dotnet } = await import(dotnetJsUrl);
const { getAssemblyExports, getConfig } = dotnetBootJsUrl ? await dotnet.withConfigSrc(dotnetBootJsUrl).create() : await dotnet.create();
const config = getConfig();
assemblyExports = await getAssemblyExports(config.mainAssemblyName);
console.log('Worker initialized successfully');
} catch (err) {
startupError = err.message;
}
result = true;
break;
case 'generateQR':
result = assemblyExports.QRGenerator.Generate(e.data.text, e.data.size);
break;
default:
throw new Error(`Unknown command: ${command}`);
}
```
Contributor guide
Assessment
This issue has not been assessed yet.