Skip to content

Commit 409e2cf

Browse files
committed
should fix the "document does not appear to be an SVG"
1 parent 116077a commit 409e2cf

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

‎webpack.config.js‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ const htmlWebpackPluginCommon = {
3030
// When this changes, the path for all JS files will change, bypassing any HTTP caches
3131
const CACHE_EPOCH = 'pentapod';
3232

33+
/*
34+
* scratch-storage resolves to its source (the alias below), and its source requires three files
35+
* it falls back to when an asset cannot be loaded -- the grey question mark, the empty vector,
36+
* the silent sound -- expecting arraybuffers, as its own build gives it. This config's url-loader
37+
* would hand it data-URI strings instead, and Buffer.from(string) makes a "default costume" out of
38+
* the text of a data URI, which is not an SVG. Every project with one missing costume then
39+
* failed to load outright, where it used to show a blank costume.
40+
*/
41+
const STORAGE_BUILTINS = /scratch-storage[\\/]src[\\/]builtins[\\/]/;
42+
3343
const base = {
3444
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
3545
devtool: process.env.SOURCEMAP || (process.env.NODE_ENV === 'production' ? false : 'cheap-module-source-map'),
@@ -93,6 +103,11 @@ const base = {
93103
presets: ['@babel/preset-env', '@babel/preset-react']
94104
}
95105
},
106+
{
107+
test: /\.(png|svg|wav)$/,
108+
include: STORAGE_BUILTINS,
109+
loader: 'arraybuffer-loader'
110+
},
96111
{
97112
test: /\.css$/,
98113
use: [{
@@ -163,6 +178,7 @@ module.exports = [
163178
rules: base.module.rules.concat([
164179
{
165180
test: /\.(svg|png|wav|mp3|gif|jpg|woff2|hex|mp4)$/,
181+
exclude: STORAGE_BUILTINS,
166182
loader: 'url-loader',
167183
options: {
168184
limit: 2048,
@@ -287,6 +303,7 @@ module.exports = [
287303
rules: base.module.rules.concat([
288304
{
289305
test: /\.(svg|png|wav|mp3|gif|jpg|woff2|hex|mp4)$/,
306+
exclude: STORAGE_BUILTINS,
290307
loader: 'url-loader',
291308
options: {
292309
limit: 2048,

0 commit comments

Comments
 (0)