element-web/recorder-worklet-loader.js

38 lines
1.1 KiB
JavaScript
Raw Normal View History

2023-11-18 21:37:30 +01:00
/*
2024-09-06 16:44:31 +02:00
Copyright 2024 New Vector Ltd.
2023-11-18 21:37:30 +01:00
Copyright 2023 The Matrix.org Foundation C.I.C.
2024-09-06 16:44:31 +02:00
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
Please see LICENSE files in the repository root for full details.
2023-11-18 21:37:30 +01:00
*/
// Inspired by https://github.com/reklawnos/worklet-loader which doesn't
// formally support Webpack 5
const SingleEntryPlugin = require("webpack/lib/SingleEntryPlugin");
module.exports = function () {};
module.exports.pitch = function pitch(request) {
const cb = this.async();
const filename = "recorder.worklet.js";
const compiler = this._compilation.createChildCompiler("worker", {
filename,
chunkFilename: `[id].${filename}`,
namedChunkFilename: null,
});
new SingleEntryPlugin(this.context, `!!${request}`, "main").apply(compiler);
compiler.runAsChild((err, entries, compilation) => {
if (err) {
return cb(err);
}
if (entries[0]) {
return cb(null, `module.exports = __webpack_public_path__ + ${JSON.stringify([...entries[0].files][0])};`);
2023-11-18 21:37:30 +01:00
}
return cb(null, null);
});
};