Playground: use UMD to load storage as global ()

* Playground: use UMD to load storage as global

It appears that `expose-loader` is not compatible with WebPack's UMD
exporter, so the VM playground broke when I converted `scratch-storage`
to use UMD. This change causes the playground to load `scratch-storage`
as an independent script and relies on its UMD loader to expose it as a
global. Bonus points: we get better source mapping this way.

* Playground: tell eslint about global ScratchStorage
This commit is contained in:
Chris Willis-Ford 2017-10-17 14:40:11 -07:00 committed by Ray Schamp
parent ceb47bd765
commit d8a3e659d5
3 changed files with 7 additions and 9 deletions

View file

@ -66,7 +66,9 @@
<!-- FPS counter, Syntax highlighter, Blocks, Renderer --> <!-- FPS counter, Syntax highlighter, Blocks, Renderer -->
<script src="./vendor.js"></script> <script src="./vendor.js"></script>
<!-- VM Worker --> <!-- Storage module -->
<script src="./scratch-storage.js"></script>
<!-- VM -->
<script src="./scratch-vm.js"></script> <script src="./scratch-vm.js"></script>
<!-- Playground --> <!-- Playground -->
<script src="./playground.js"></script> <script src="./playground.js"></script>

View file

@ -46,7 +46,7 @@ window.onload = function () {
const vm = new window.VirtualMachine(); const vm = new window.VirtualMachine();
Scratch.vm = vm; Scratch.vm = vm;
const storage = new Scratch.Storage(); const storage = new ScratchStorage(); /* global ScratchStorage */
const AssetType = storage.AssetType; const AssetType = storage.AssetType;
storage.addWebSource([AssetType.Project], getProjectUrl); storage.addWebSource([AssetType.Project], getProjectUrl);
storage.addWebSource([AssetType.ImageVector, AssetType.ImageBitmap, AssetType.Sound], getAssetUrl); storage.addWebSource([AssetType.ImageVector, AssetType.ImageBitmap, AssetType.Sound], getAssetUrl);

View file

@ -77,9 +77,7 @@ module.exports = [
// Audio // Audio
'scratch-audio', 'scratch-audio',
// Renderer // Renderer
'scratch-render', 'scratch-render'
// Storage
'scratch-storage'
] ]
}, },
output: { output: {
@ -111,10 +109,6 @@ module.exports = [
{ {
test: require.resolve('scratch-render'), test: require.resolve('scratch-render'),
loader: 'expose-loader?RenderWebGL' loader: 'expose-loader?RenderWebGL'
},
{
test: require.resolve('scratch-storage'),
loader: 'expose-loader?Scratch.Storage'
} }
]) ])
}, },
@ -124,6 +118,8 @@ module.exports = [
to: 'media' to: 'media'
}, { }, {
from: 'node_modules/highlightjs/styles/zenburn.css' from: 'node_modules/highlightjs/styles/zenburn.css'
}, {
from: 'node_modules/scratch-storage/dist/web'
}, { }, {
from: 'src/playground' from: 'src/playground'
}]) }])