webpack / webpack.js.org

Repository for webpack documentation and more!
https://webpack.js.org
Creative Commons Attribution 4.0 International
2.21k stars 3.31k forks source link

Document webpack change: feat: introduce a new syntax for worklets - `*context.audioWorklet.addModule()` #6869

Open webpack-bot opened 1 year ago

webpack-bot commented 1 year ago

A pull request by @alexander-akait was merged and maintainers requested a documentation change.

See pull request: https://github.com/webpack/webpack/pull/17212


Part of https://github.com/webpack/webpack/issues/11543, currently you can't use

myAudioContext.audioWorklet.addModule('./audio-worklet.js')

But now you can use:

module.exports = {
    output: {
        filename: "[name].js"
    },
    target: "web",
    module: {
        rules: [
            {
                test: /\.[cm]?js$/,
                parser: {
                    worker: [
                        "*context.audioWorklet.addModule()",
                        "*audioWorklet.addModule()",
                        // *addModule() is not valid syntax
                        "..."
                    ]
                }
            }
        ]
    }
};

Using * allow to build worklet from a variable (i.e. *context means take context variable and check members after it, it works only on start of line, i.e. context.foo*.addModule() doesn't supported), i.e.

const context = new AudioContext();
context.audioWorklet.addModule(new URL("./worklet.js", import.meta.url));

let audioWorklet = (new AudioContext()).audioWorklet;
audioWorklet.addModule(new URL("./worklet.js", import.meta.url));

Note - you can use it not only for worklets, for any custom syntax with call and member expressions

Summary

🤖 Generated by Copilot at 20c6900

This pull request adds a new feature to the WorkerPlugin that allows using a special syntax for worker specifiers that match a worklet API. It also adds several test files and helpers to verify the functionality and compatibility of the feature.

Details

🤖 Generated by Copilot at 20c6900

steverep commented 4 months ago

@alexander-akait I'm having to dig into the code to understand what exactly the new syntax will match. Could you add some documentation for this with some match / won't match examples?

For example, would the syntax as written be expected to match:

    await this._context.audioWorklet.addModule(
      new URL("./recorder.worklet.js", import.meta.url)
    );