Skip to content

Commit

Permalink
fix: load web worker script from a correct location [PT-187028887]
Browse files Browse the repository at this point in the history
  • Loading branch information
pjanik committed Feb 12, 2024
1 parent cdbaf93 commit f6dbc16
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/tecrock-simulation/src/worker-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import { ISerializedField } from "./plates-model/field";
export type EventName = ModelWorkerMsg["type"];
export type ResponseHandler = (response: any) => void;

declare var __WEBPACK_DEPLOY_PATH__: string;

let _requestId = 0;
const getRequestId = () => ++_requestId;

class WorkerController {
// Plate tectonics model, handles all the aspects of simulation which are not related to view and interaction.
modelWorker = new window.Worker(`modelWorker.js${window.location.search}`);
modelWorker = new window.Worker(`${__WEBPACK_DEPLOY_PATH__}/modelWorker.js${window.location.search}`);
modelState = "notRequested";
// Messages to model worker are queued before model is loaded.
modelMessagesQueue: IncomingModelWorkerMsg[] = [];
Expand Down
6 changes: 5 additions & 1 deletion packages/tecrock-simulation/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,11 @@ module.exports = {
template: './src/index.html',
favicon: './public/favicon.ico',
publicPath: DEPLOY_PATH,
})] : [])
})] : []),
// Define DEPLOY_PATH globally so it can be used to load Web Worker script from a correct location
new webpack.DefinePlugin({
'__WEBPACK_DEPLOY_PATH__': JSON.stringify(DEPLOY_PATH || ".")
})
]
}

Expand Down

0 comments on commit f6dbc16

Please sign in to comment.