|
| 1 | +// Wire the runtime asset-path global into webpack's publicPath. |
| 2 | +// |
| 3 | +// Image imports (e.g. `import bot from './ai-bot-body.png'`) and any |
| 4 | +// other webpack `asset` / `asset/resource` modules resolve their URLs |
| 5 | +// against webpack's runtime `publicPath`. The default is `'auto'`, |
| 6 | +// which infers the path from where the host page loaded the script — |
| 7 | +// not what we want when the package is embedded into a consumer like |
| 8 | +// apps's dashboard, which serves these images from a different base |
| 9 | +// path (e.g. `/blockly/media/skins/ailab/`). |
| 10 | +// |
| 11 | +// Webpack exposes `__webpack_public_path__` as a magic variable: any |
| 12 | +// assignment to it at runtime updates the publicPath used by |
| 13 | +// subsequently-evaluated asset modules. We pull the desired base from |
| 14 | +// the same global the dataset/manifest loader already uses |
| 15 | +// (`__ml_playground_asset_public_path__`), so the consumer has one |
| 16 | +// knob to turn. |
| 17 | +// |
| 18 | +// This module MUST be imported before any module that pulls in an |
| 19 | +// image — i.e. it should be the first import in the entry file. |
| 20 | +// ECMAScript guarantees depth-first evaluation order: when an entry |
| 21 | +// does `import './setPublicPath'; import './index';`, this module's |
| 22 | +// body runs to completion before `./index` starts evaluating, so all |
| 23 | +// downstream asset modules see the updated `__webpack_public_path__`. |
| 24 | +// `__webpack_public_path__` is a webpack magic variable: at build time |
| 25 | +// webpack rewrites assignments to it as updates to its runtime |
| 26 | +// `__webpack_require__.p`. ESLint doesn't understand this — it sees a |
| 27 | +// `let` with a single assignment and no read, hence the disables. |
| 28 | +/* eslint-disable prefer-const, @typescript-eslint/no-unused-vars */ |
| 29 | +declare let __webpack_public_path__: string; |
| 30 | +__webpack_public_path__ = |
| 31 | + (global as unknown as Record<string, string>) |
| 32 | + .__ml_playground_asset_public_path__ || './'; |
| 33 | +/* eslint-enable prefer-const, @typescript-eslint/no-unused-vars */ |
0 commit comments