Skip to content

Commit 0115a4d

Browse files
committed
allow using global variable to configure worker module public path, enabling using the library module directly in another application without cordova
1 parent 516341b commit 0115a4d

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/browser/src/createQRScannerInternal.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -368,13 +368,17 @@ module.exports = function () {
368368
function initialize(success, error) {
369369
if (scanWorker === null) {
370370
// Automatic public path doesn't work here with the complicated build and cordova magic.
371-
// We derive our own public path based on injected environment variable.
371+
// We derive our own public path based on injected environment variable, or a runtime
372+
// global variable. The environment variable is used by cordova test framework.
373+
// The global variable is used when using the internal implementation directly in
374+
// another application without using cordova.
372375
// After instantiating the url, we set it back to its original value.
373376
// https://mmazzarolo.com/blog/2021-09-03-loading-web-workers-using-webpack-5/
374377
const original__webpack_public_path__ = __webpack_public_path__;
375378

376-
if (process.env.WORKER_PUBLIC_PATH !== null) {
377-
__webpack_public_path__ = process.env.WORKER_PUBLIC_PATH;
379+
const worker_public_path = window.QRSCANNER_WORKER_PUBLIC_PATH || process.env.WORKER_PUBLIC_PATH
380+
if (worker_public_path !== null) {
381+
__webpack_public_path__ = worker_public_path;
378382
}
379383

380384
scanWorker = new Worker(

0 commit comments

Comments
 (0)