diff --git a/packages/tecrock-simulation/src/worker-controller.ts b/packages/tecrock-simulation/src/worker-controller.ts index aeac52e0..2c3bb4ef 100644 --- a/packages/tecrock-simulation/src/worker-controller.ts +++ b/packages/tecrock-simulation/src/worker-controller.ts @@ -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[] = []; diff --git a/packages/tecrock-simulation/webpack.config.js b/packages/tecrock-simulation/webpack.config.js index 519f6bd6..2c6bc18c 100644 --- a/packages/tecrock-simulation/webpack.config.js +++ b/packages/tecrock-simulation/webpack.config.js @@ -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 || ".") + }) ] }