Commit 8fdb564
committed
fix: set publicPath for Experience CS
RaspberryPiFoundation/experience-cs#23
We recently embedded the scratch-gui within our Experience CS app.
We have since noticed a number of issues with assets failing to load within the
browser, for example the browser is attempting to load assets from URLs relative
to the webpack entry point (rather than from the root or from `/scratch-gui/`).
After some investigation it turns out that is due to the fact that the webpack
option `publicPath` had been set to `auto` [1].
For our purposes we want assets to be served from `/scratch-gui`, and I can't
see the need to make this configurable at this stage, therefore I have hardcoded
this value for now as that also makes building the package less prone to error.
However if we were to push changes upstream, then I think it would make sense to
use an ASSET_PATH environment variable.
[1]
https://webpack.js.org/guides/public-path/
```
**Automatic publicPath**
There are chances that you don't know what the publicPath will be in advance,
and webpack can handle it automatically for you by determining the public path
from variables like import.meta.url, document.currentScript, script.src or
self.location.
```1 parent e56792a commit 8fdb564
1 file changed
+3
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
| |||
103 | 105 | | |
104 | 106 | | |
105 | 107 | | |
106 | | - | |
| 108 | + | |
107 | 109 | | |
108 | 110 | | |
109 | 111 | | |
| |||
0 commit comments