Skip to content
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

Merged
merged 6 commits into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions examples/blockly-parcel/.parcelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": ["@parcel/config-default"],
"reporters": ["...", "parcel-reporter-static-files-copy"]
}

32 changes: 32 additions & 0 deletions examples/blockly-parcel/README.md
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
```
20 changes: 20 additions & 0 deletions examples/blockly-parcel/package.json
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"
}
}
61 changes: 61 additions & 0 deletions examples/blockly-parcel/public/generator.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/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>
61 changes: 61 additions & 0 deletions examples/blockly-parcel/public/index.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>
61 changes: 61 additions & 0 deletions examples/blockly-parcel/public/locale.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>
34 changes: 34 additions & 0 deletions examples/blockly-parcel/src/generator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* @license
* Copyright 2021 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @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',
{
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);
});
});
29 changes: 29 additions & 0 deletions examples/blockly-parcel/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* @license
* Copyright 2021 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @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);
});
});
34 changes: 34 additions & 0 deletions examples/blockly-parcel/src/locale.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* @license
* Copyright 2021 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @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);
});
});