-
Notifications
You must be signed in to change notification settings - Fork 627
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bundling Blockly with Parcel #682
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"extends": ["@parcel/config-default"], | ||
"reporters": ["...", "parcel-reporter-static-files-copy"] | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
[Home](../README.md) | ||
|
||
# blockly-parcel-sample [![Built on Blockly](https://tinyurl.com/built-on-blockly)](https://github.com/google/blockly) | ||
|
||
This sample shows how to load Blockly with [Parcel V2 bundler](https://v2.parceljs.org/). | ||
|
||
The example mirrors a similar sample for [Webpack bundler](../blockly-webpack/README.md). | ||
|
||
## Installation | ||
|
||
``` | ||
npm install | ||
``` | ||
|
||
## Running | ||
|
||
``` | ||
npm run start | ||
``` | ||
|
||
### Browsing | ||
- [http://localhost:1234/index.html](http://localhost:1234/index.html): Loads Blockly with all the defaults (JavaScript and English lang). | ||
- [http://localhost:1234/generator.html](http://localhost:1234/generator.html): Loads Blockly with the Python generator. | ||
- [http://localhost:1234/locale.html](http://localhost:1234/locale.html): Loads Blockly with the French locale files. | ||
|
||
|
||
|
||
## Building | ||
|
||
``` | ||
npm run build | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "blockly-parcel-sample", | ||
"version": "0.0.0", | ||
"private": true, | ||
"scripts": { | ||
"audit": "npm audit fix", | ||
"update": "npm update", | ||
"start": "parcel public/index.html", | ||
"build": "parcel build public/index.html" | ||
}, | ||
"devDependencies": { | ||
"blockly": "^5.2", | ||
"parcel": "next", | ||
"parcel-reporter-static-files-copy": "^1.3" | ||
}, | ||
"staticFiles": { | ||
"staticPath": "node_modules/blockly/media", | ||
"staticOutPath": "media" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<title>Blockly - Loading with Parcel</title> | ||
<style> | ||
html, | ||
body { | ||
height: 100%; | ||
margin: 0; | ||
} | ||
|
||
#blocklyDiv { | ||
height: 100%; | ||
} | ||
|
||
#blocklyButton { | ||
float: right; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<nav> | ||
<a href="./index.html">Default</a> | ||
<a href="./generator.html">Custom generator</a> | ||
<a href="./locale.html">Custom locale</a> | ||
<button id="blocklyButton">Convert</button> | ||
</nav> | ||
<div id='blocklyDiv'> | ||
</div> | ||
|
||
<script type='module' src='../src/generator.js'></script> | ||
|
||
<xml xmlns="https://developers.google.com/blockly/xml" id="toolbox" style="display: none"> | ||
<block type="controls_ifelse"></block> | ||
<block type="logic_compare"></block> | ||
<block type="logic_operation"></block> | ||
<block type="controls_repeat_ext"> | ||
<value name="TIMES"> | ||
<shadow type="math_number"> | ||
<field name="NUM">10</field> | ||
</shadow> | ||
</value> | ||
</block> | ||
<block type="logic_operation"></block> | ||
<block type="logic_negate"></block> | ||
<block type="logic_boolean"></block> | ||
<block type="logic_null" disabled="true"></block> | ||
<block type="logic_ternary"></block> | ||
<block type="text_charAt"> | ||
<value name="VALUE"> | ||
<block type="variables_get"> | ||
<field name="VAR">text</field> | ||
</block> | ||
</value> | ||
</block> | ||
</xml> | ||
</body> | ||
|
||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<title>Blockly - Loading with Parcel</title> | ||
<style> | ||
html, | ||
body { | ||
height: 100%; | ||
margin: 0; | ||
} | ||
|
||
#blocklyDiv { | ||
height: 100%; | ||
} | ||
|
||
#blocklyButton { | ||
float: right; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<nav> | ||
<a href="./index.html">Default</a> | ||
<a href="./generator.html">Custom generator</a> | ||
<a href="./locale.html">Custom locale</a> | ||
<button id="blocklyButton">Convert</button> | ||
</nav> | ||
<div id='blocklyDiv'> | ||
</div> | ||
|
||
<script type='module' src='../src/index.js'></script> | ||
|
||
<xml xmlns="https://developers.google.com/blockly/xml" id="toolbox" style="display: none"> | ||
<block type="controls_ifelse"></block> | ||
<block type="logic_compare"></block> | ||
<block type="logic_operation"></block> | ||
<block type="controls_repeat_ext"> | ||
<value name="TIMES"> | ||
<shadow type="math_number"> | ||
<field name="NUM">10</field> | ||
</shadow> | ||
</value> | ||
</block> | ||
<block type="logic_operation"></block> | ||
<block type="logic_negate"></block> | ||
<block type="logic_boolean"></block> | ||
<block type="logic_null" disabled="true"></block> | ||
<block type="logic_ternary"></block> | ||
<block type="text_charAt"> | ||
<value name="VALUE"> | ||
<block type="variables_get"> | ||
<field name="VAR">text</field> | ||
</block> | ||
</value> | ||
</block> | ||
</xml> | ||
</body> | ||
|
||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<title>Blockly - Loading with Parcel</title> | ||
<style> | ||
html, | ||
body { | ||
height: 100%; | ||
margin: 0; | ||
} | ||
|
||
#blocklyDiv { | ||
height: 100%; | ||
} | ||
|
||
#blocklyButton { | ||
float: right; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<nav> | ||
<a href="./index.html">Default</a> | ||
<a href="./generator.html">Custom generator</a> | ||
<a href="./locale.html">Custom locale</a> | ||
<button id="blocklyButton">Convert</button> | ||
</nav> | ||
<div id='blocklyDiv'> | ||
</div> | ||
|
||
<script type='module' src='../src/locale.js'></script> | ||
|
||
<xml xmlns="https://developers.google.com/blockly/xml" id="toolbox" style="display: none"> | ||
<block type="controls_ifelse"></block> | ||
<block type="logic_compare"></block> | ||
<block type="logic_operation"></block> | ||
<block type="controls_repeat_ext"> | ||
<value name="TIMES"> | ||
<shadow type="math_number"> | ||
<field name="NUM">10</field> | ||
</shadow> | ||
</value> | ||
</block> | ||
<block type="logic_operation"></block> | ||
<block type="logic_negate"></block> | ||
<block type="logic_boolean"></block> | ||
<block type="logic_null" disabled="true"></block> | ||
<block type="logic_ternary"></block> | ||
<block type="text_charAt"> | ||
<value name="VALUE"> | ||
<block type="variables_get"> | ||
<field name="VAR">text</field> | ||
</block> | ||
</value> | ||
</block> | ||
</xml> | ||
</body> | ||
|
||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* @license | ||
* | ||
* Copyright 2021 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* @fileoverview Example of including Blockly using Parcel with | ||
* the Python generator. | ||
* @author ettinger.boris@gmail.com (Boris Ettinger) | ||
*/ | ||
|
||
import * as Blockly from 'blockly/core'; | ||
import 'blockly/blocks'; | ||
import 'blockly/python'; | ||
|
||
import * as En from 'blockly/msg/en'; | ||
Blockly.setLocale(En); | ||
|
||
|
||
document.addEventListener("DOMContentLoaded", function () { | ||
const workspace = Blockly.inject('blocklyDiv', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be an indent of 2 instead of 4. |
||
{ | ||
toolbox: document.getElementById('toolbox'), | ||
media: 'media/' | ||
}); | ||
|
||
const lang = 'Python'; | ||
const button = document.getElementById('blocklyButton'); | ||
button.addEventListener('click', function () { | ||
alert("Check the console for the generated output."); | ||
const code = Blockly[lang].workspaceToCode(workspace); | ||
console.log(code); | ||
}) | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* @license | ||
* | ||
* Copyright 2021 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can now be replaced with:
|
||
*/ | ||
|
||
/** | ||
* @fileoverview Example of including Blockly using Parcel with | ||
* defaults: (English lang & JavaScript generator). | ||
* @author ettinger.boris@gmail.com (Boris Ettinger) | ||
*/ | ||
|
||
import * as Blockly from 'blockly'; | ||
|
||
document.addEventListener("DOMContentLoaded", function () { | ||
const workspace = Blockly.inject('blocklyDiv', | ||
{ | ||
toolbox: document.getElementById('toolbox'), | ||
media: 'media/' | ||
}); | ||
|
||
const lang = 'JavaScript'; | ||
const button = document.getElementById('blocklyButton'); | ||
button.addEventListener('click', function () { | ||
alert("Check the console for the generated output."); | ||
const code = Blockly[lang].workspaceToCode(workspace); | ||
console.log(code); | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: add ; |
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* @license | ||
* | ||
* Copyright 2021 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* @fileoverview Example of including Blockly using Parcel with a | ||
* custom locale: (French lang & JavaScript generator). | ||
* @author ettinger.boris@gmail.com (Boris Ettinger) | ||
*/ | ||
|
||
import * as Blockly from 'blockly/core'; | ||
import 'blockly/blocks'; | ||
import 'blockly/javascript'; | ||
|
||
import * as Fr from 'blockly/msg/fr'; | ||
Blockly.setLocale(Fr); | ||
|
||
|
||
document.addEventListener("DOMContentLoaded", function () { | ||
const workspace = Blockly.inject('blocklyDiv', | ||
{ | ||
toolbox: document.getElementById('toolbox'), | ||
media: 'media/' | ||
}); | ||
|
||
const lang = 'JavaScript'; | ||
const button = document.getElementById('blocklyButton'); | ||
button.addEventListener('click', function () { | ||
alert("Check the console for the generated output."); | ||
const code = Blockly[lang].workspaceToCode(workspace); | ||
console.log(code); | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: add ; |
||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Add a line between imports and the first line of code.