Skip to content

Commit 78c157f

Browse files
committed
fix: set publicPath for Experience CS
**Background** We use a fork of `scratch-gui` in the Experience CS app for rendering scratch projects. This fork is essential as it allows us to specify where asset URLs are served from (otherwise they are broken). We also use this fork to tweak the UI and expose additional functionality. Up until now this fork has been based off of a Google fork (which provides better keyboard accessiblity), but after a number of user facing bugs we have decided to base our fork off of the official `scratch-gui` repo. These Google changes are in the process of being merged upstreamed and so we think this is the right approach. The official `scratch-gui` project has moved on since the Google fork and relies on a newer version of `scratch-storage`. **The problem** `scratch-gui` uses `scratch-storage` for loading scratch project files via a Web Worker script so it can do so using a background thread [1]. This script is loaded dynamically and relies on the webpack `output.publicPath` option [2] to determine where to load this script from. Unfortunately we need this script to load succesfully for scratch-gui to work and as with `scratch-gui` itself, therefore we also need to configure `output.publicPath` for `scratch-storage`. 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. [1] https://github.com/RaspberryPiFoundation/scratch-storage/blob/develop/src/FetchWorkerTool.ts http://localhost:3000/scratch-gui/chunks/fetch-worker.7a0adc94df277ffeb963.js [2] https://webpack.js.org/guides/public-path/
1 parent 4e9518d commit 78c157f

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

webpack.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ const webpack = require('webpack');
33

44
const ScratchWebpackConfigBuilder = require('scratch-webpack-configuration');
55

6+
7+
const ASSET_PATH = '/scratch-gui/';
8+
69
const baseConfig = new ScratchWebpackConfigBuilder(
710
{
811
rootPath: path.resolve(__dirname),
@@ -32,6 +35,7 @@ const webConfig = baseConfig.clone()
3235
type: 'umd2'
3336
},
3437
path: path.resolve(__dirname, 'dist', 'web'),
38+
publicPath: ASSET_PATH,
3539
clean: false
3640
}
3741
});
@@ -68,6 +72,7 @@ const nodeConfig = baseConfig.clone()
6872
},
6973
chunkFormat: 'commonjs',
7074
path: path.resolve(__dirname, 'dist', 'node'),
75+
publicPath: ASSET_PATH,
7176
clean: false
7277
}
7378
})

0 commit comments

Comments
 (0)