From 4ceeebb257697cf797441f9d4fb22832fc8f95b5 Mon Sep 17 00:00:00 2001 From: "Michael \"Z\" Goddard" Date: Mon, 30 Apr 2018 11:53:01 -0400 Subject: [PATCH] Use src/index as browser entry point Use src/index.js as the entry by default in tools building scratch-vm into a larger package. This saves file space by excluding extra webpack boilerplate and may allow for deeper optimizations. Depend on script dependencies for downstream webpack. For another package to build in scratch-vm's dependencies without them already being built into a consumed webpack build they need to be listed as dependencies. This can benefit large projects that reuse the same dependencies multiple times. Node will still use the main entry point and its webpack build leaves the dependencies as external references so it may reuse common modules in Node as well as in a build a browser environment. --- package.json | 35 ++++++++++++++++++----------------- src/playground/index.html | 2 +- webpack.config.js | 17 +++++++++++++---- 3 files changed, 32 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index cadbb07c553..e9892030b3e 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "url": "git+ssh://git@github.com/LLK/scratch-vm.git" }, "main": "./dist/node/scratch-vm.js", - "browser": "./dist/web/scratch-vm.js", + "browser": "./src/index.js", "scripts": { "build": "webpack --progress --colors --bail", "coverage": "tap ./test/{unit,integration}/*.js --coverage --coverage-report=lcov", @@ -27,6 +27,22 @@ "watch": "webpack --progress --colors --watch", "version": "json -f package.json -I -e \"this.repository.sha = '$(git log -n1 --pretty=format:%H)'\"" }, + "dependencies": { + "arraybuffer-loader": "^1.0.3", + "decode-html": "2.0.0", + "diff-match-patch": "1.0.0", + "escape-html": "1.0.3", + "format-message": "5.2.1", + "htmlparser2": "3.9.2", + "immutable": "3.8.1", + "jszip": "^3.1.5", + "minilog": "3.1.0", + "nets": "3.2.0", + "scratch-parser": "4.1.1", + "socket.io-client": "2.0.4", + "text-encoding": "0.6.4", + "worker-loader": "^1.1.1" + }, "devDependencies": { "adm-zip": "0.4.7", "arraybuffer-loader": "^1.0.3", @@ -36,42 +52,27 @@ "babel-preset-env": "^1.6.1", "canvas-toBlob": "1.0.0", "copy-webpack-plugin": "^4.5.1", - "decode-html": "2.0.0", - "diff-match-patch": "1.0.0", - "escape-html": "1.0.3", "eslint": "^4.5.0", "eslint-config-scratch": "^5.0.0", "expose-loader": "0.7.5", "file-loader": "^1.1.6", - "format-message": "5.2.1", "format-message-cli": "5.2.1", "gh-pages": "^1.1.0", - "highlightjs": "^9.8.0", - "htmlparser2": "3.9.2", - "immutable": "3.8.1", "in-publish": "^2.0.0", "json": "^9.0.4", - "jszip": "^3.1.5", "lodash.defaultsdeep": "4.6.0", - "minilog": "3.1.0", - "nets": "3.2.0", "pngjs": "^3.3.2", - "promise": "8.0.1", "scratch-audio": "latest", "scratch-blocks": "latest", - "scratch-parser": "4.1.1", "scratch-render": "latest", "scratch-storage": "^0.4.0", "scratch-translate-extension-languages": "0.0.20180521154850", "script-loader": "0.7.2", - "socket.io-client": "2.0.4", "stats.js": "^0.17.0", "tap": "^11.0.1", - "text-encoding": "0.6.4", "tiny-worker": "^2.1.1", "webpack": "^4.8.0", "webpack-cli": "^2.0.15", - "webpack-dev-server": "^3.1.3", - "worker-loader": "^1.1.1" + "webpack-dev-server": "^3.1.3" } } diff --git a/src/playground/index.html b/src/playground/index.html index be633b620d8..7f07f92677c 100644 --- a/src/playground/index.html +++ b/src/playground/index.html @@ -79,7 +79,7 @@

Scratch VM Benchmark

- + diff --git a/webpack.config.js b/webpack.config.js index 6eca43f5f18..d87ece7bfd2 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -69,6 +69,19 @@ module.exports = [ output: { libraryTarget: 'commonjs2', path: path.resolve('dist', 'node') + }, + externals: { + 'decode-html': true, + 'escape-html': true, + 'format-message': true, + 'htmlparser2': true, + 'immutable': true, + 'jszip': true, + 'minilog': true, + 'nets': true, + 'scratch-parser': true, + 'socket.io-client': true, + 'text-encoding': true } }), // Playground @@ -79,8 +92,6 @@ module.exports = [ 'vendor': [ // FPS counter 'stats.js/build/stats.min.js', - // Syntax highlighter - 'highlightjs/highlight.pack.min.js', // Scratch Blocks 'scratch-blocks/dist/vertical.js', // Audio @@ -139,8 +150,6 @@ module.exports = [ new CopyWebpackPlugin([{ from: 'node_modules/scratch-blocks/media', to: 'media' - }, { - from: 'node_modules/highlightjs/styles/zenburn.css' }, { from: 'node_modules/scratch-storage/dist/web' }, {