Use Webpack to generate the whole playground

The previous configuration mixed Webpack output with static content in
order to create the playground. This change moves that static content
from `/playground/` into `/src/playground/` and adds a Webpack rule to
copy it into the playground as part of the build.

On the surface this might seem unnecessary, but it provides at least two
benefits:
- It's no longer possible to accidentally load stale build output
  through `webpack-dev-server` in the event of a misconfiguration. This
  was very easy in the previous configuration, and might in fact be the
  only way that `webpack-dev-server` ever worked for this repository.
- It's simpler to ensure that various rules apply to the hand-authored
  content and not build outputs. This includes lint rules, `.gitignore`,
  IDE symbol search paths, etc.
This commit is contained in:
Christopher Willis-Ford 2017-02-10 14:21:37 -08:00
parent 99be466aa7
commit 243d68f88b
5 changed files with 24 additions and 29 deletions

8
.gitignore vendored
View file

@ -14,10 +14,4 @@ npm-*
# Build
/dist
/playground/assets
/playground/media
/playground/scratch-vm.js
/playground/scratch-vm.js.map
/playground/vendor.js
/playground/vendor.js.map
/playground/zenburn.css
/playground

View file

@ -1,4 +1,3 @@
var loadProject = function () {
var id = location.hash.substring(1);
if (id.length < 1 || !isFinite(id)) {
@ -83,7 +82,7 @@ window.onload = function() {
var threadexplorer = document.getElementById('threadexplorer');
var cachedThreadJSON = '';
var updateThreadExplorer = function (newJSON) {
if (newJSON != cachedThreadJSON) {
if (newJSON !== cachedThreadJSON) {
cachedThreadJSON = newJSON;
threadexplorer.innerHTML = cachedThreadJSON;
window.hljs.highlightBlock(threadexplorer);
@ -125,7 +124,7 @@ window.onload = function() {
var targetOption = document.createElement('option');
targetOption.setAttribute('value', data.targetList[i].id);
// If target id matches editingTarget id, select it.
if (data.targetList[i].id == data.editingTarget) {
if (data.targetList[i].id === data.editingTarget) {
targetOption.setAttribute('selected', 'selected');
}
targetOption.appendChild(
@ -213,7 +212,7 @@ window.onload = function() {
// Feed keyboard events as VM I/O events.
document.addEventListener('keydown', function (e) {
// Don't capture keys intended for Blockly inputs.
if (e.target != document && e.target != document.body) {
if (e.target !== document && e.target !== document.body) {
return;
}
window.vm.postIOData('keyboard', {
@ -230,7 +229,7 @@ window.onload = function() {
isDown: false
});
// E.g., prevent scroll.
if (e.target != document && e.target != document.body) {
if (e.target !== document && e.target !== document.body) {
e.preventDefault();
}
});

View file

@ -5,7 +5,7 @@ var webpack = require('webpack');
var base = {
devServer: {
contentBase: path.resolve(__dirname, 'playground'),
contentBase: false,
host: '0.0.0.0',
port: process.env.PORT || 8073
},
@ -108,6 +108,8 @@ module.exports = [
to: 'media'
}, {
from: 'node_modules/highlightjs/styles/zenburn.css'
}, {
from: 'src/playground'
}])
])
})