angular / angular/angular-cli

Worklet support

オープン
#29,130 コメント 5 件 リアクション 14 件 担当者 0 名 GitHub で見る
angular/build:application area: @angular/build feature feature: insufficient votes
主要言語
TypeScript
スター
27k
フォーク
11.8k
平均マージ
14時間 23分
マージ済み PR(30日)
162

説明

### Which @angular/* package(s) are relevant/related to the feature request?

compiler

### Description

The [worklets](https://developer.mozilla.org/en-US/docs/Web/API/Worklet) are light weighted version of web workers. Currently Angular supports web workers, but not worklets, this makes us unable to make use of Angular's Typescript and bundling support when writing a worklet (i.e. we have to write the worklet in pure Javasctript, or deal with compiling and bundling ourselves).

### Proposed solution

Support worklet like web workers.

### Alternatives considered

For now we have come to a hacky workaround:

1. Write the worklet as if it's a web worker. This is perfecly supported by Angular. Now the problem is, to load the compiled worker script, we don't have a trivial way to get its URL.

2. Wrap the worker code like this:

```js
if (typeof self !== "undefined") {
postMessage(self.location.href);
} else {
// do the worklet thing
}
```
When `self` is not `undefined`, we know this script is loaded as a webworker (in a worklet context it would be `undefined`). In this case, send the script's location by `postMessage`.

3. When trying to load the worklet, first load it as a web worker, wait for it to report the location, then terminate the worker and use the location to load the worklet.

E.g. load an audio worklet:
```typescript
// probe worker url
const worker = new Worker(
new URL("path/to/the/worker", import.meta.url),
);

const url = await new Promise((resolve, reject) => {
worker.onmessage = (e) => {
resolve(e.data);
worker.terminate();
};

worker.onmessageerror = reject;
});

await audioContext.audioWorklet.addModule(url);
```

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

まず、コンパイラに既存の web-worker サポートを読み、この issue で説明されている Worklet API と比較します。Angular が worklet に対して同等の TypeScript コンパイルおよびバンドリングのサポートを提供し、要求された読み込みフローをカバーできれば作業は完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
angular, typescript
領域
build-system
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。