From 3febe3bfeb0912ebcddc7db03bdb3e29ee5a8c00 Mon Sep 17 00:00:00 2001 From: pjanik Date: Tue, 13 Feb 2024 16:38:14 +0900 Subject: [PATCH] chore: use built-in __webpack_public_path__ instead of custom global variable [PT-187028887] --- packages/tecrock-simulation/src/global.d.ts | 2 ++ packages/tecrock-simulation/src/worker-controller.ts | 4 +--- packages/tecrock-simulation/webpack.config.js | 6 +----- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/tecrock-simulation/src/global.d.ts b/packages/tecrock-simulation/src/global.d.ts index 460bc133..bcb43d0c 100644 --- a/packages/tecrock-simulation/src/global.d.ts +++ b/packages/tecrock-simulation/src/global.d.ts @@ -7,3 +7,5 @@ declare module "*.css"; declare module "*.png"; declare module "*.jpg"; declare module "*.svg"; + +declare var __webpack_public_path__: string; diff --git a/packages/tecrock-simulation/src/worker-controller.ts b/packages/tecrock-simulation/src/worker-controller.ts index 2c3bb4ef..3de5ac28 100644 --- a/packages/tecrock-simulation/src/worker-controller.ts +++ b/packages/tecrock-simulation/src/worker-controller.ts @@ -6,14 +6,12 @@ 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(`${__WEBPACK_DEPLOY_PATH__}/modelWorker.js${window.location.search}`); + modelWorker = new window.Worker(`${__webpack_public_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 2c6bc18c..519f6bd6 100644 --- a/packages/tecrock-simulation/webpack.config.js +++ b/packages/tecrock-simulation/webpack.config.js @@ -176,11 +176,7 @@ 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 || ".") - }) + })] : []) ] }