Skip to content

Commit

Permalink
chore: modify readme about how we want people to acquire Blockly (#7661)
Browse files Browse the repository at this point in the history
* chore: modify readme about how we want people to acquire Blockly

* chore: PR comments
  • Loading branch information
BeksOmega authored Dec 1, 2023
1 parent 3d3cd3f commit f363252
Showing 1 changed file with 48 additions and 34 deletions.
82 changes: 48 additions & 34 deletions scripts/package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,10 @@ blocks together to build programs. All code is free and open source.

The source for this module is in the [Blockly repo](http://github.com/google/blockly).

## Installation

You can install this package either via `npm` or `unpkg`.

### npm

```bash
npm install blockly
```

### unpkg

```html
<script src="https://unpkg.com/blockly/blockly.min.js"></script>
```

## Example Usage

```js
import Blockly from 'blockly';
import * as Blockly from 'blockly/core';
Blockly.inject('blocklyDiv', {
...
})
Expand All @@ -34,46 +18,76 @@ Blockly.inject('blocklyDiv', {

For samples on how to integrate Blockly into your project, view the list of samples at [blockly-samples](https://github.com/google/blockly-samples).

### Importing Blockly
## Installation

When you import Blockly with `import * as Blockly from 'blockly';` you'll get the default modules:
Blockly core, Blockly built-in blocks, the JavaScript generator and the English lang files.
You can install this package either via `npm` or `unpkg`.

If you need more flexibility, you'll want to define your imports more carefully:
### unpkg

```html
<script src="https://unpkg.com/blockly/blockly.min.js"></script>
```

#### Blockly Core
When importing from unpkg, you can access imports from the global namespace.

```js
import * as Blockly from 'blockly/core';
// Access Blockly.
Blockly.thing;
// Access the default blocks.
Blockly.Blocks['block_type'];
// Access the javascript generator.
javascript.javascriptGenerator;
```

### npm

```bash
npm install blockly
```

#### Blockly built in blocks
## Imports

Note: Using import of our package targets requires you to use a bundler (like webpack), since Blockly is packaged as a UMD, rather than an ESM.

```js
// Import Blockly core.
import * as Blockly from 'blockly/core';
// Import the default blocks.
import * as libraryBlocks from 'blockly/blocks';
// Import a generator.
import {javascriptGenerator} from 'blockly/javascript';
// Import a message file.
import * as En from 'blockly/msg/en';
```

#### Blockly Generators

If your application needs to generate code from the Blockly blocks, you'll want to include a generator.
## Requires

```js
import {pythonGenerator} from 'blockly/python';
// Require Blockly core.
const Blockly = require('blockly/core');
// Require the default blocks.
const libraryBlocks = require('blockly/blocks');
// Require a generator.
const {javascriptGenerator} = require('blockly/javascript');
// Require a message file.
const En = require('blockly/msg/en');
```

to include the Python generator. You can also import `{javascriptGenerator} from 'blockly/javascript'`, `{phpGenerator} from 'blockly/php'`, `{dartGenerator} from 'blockly/dart'` and `{luaGenerator} from 'blockly/lua'`.
## Applying messages

#### Blockly Languages
Once you have the message files, you also need to apply them.

```js
import * as Fr from 'blockly/msg/fr';
Blockly.setLocale(Fr);
Blockly.setLocal(En);
```

To import the French lang files. Once you've imported the specific lang module, you'll also want to set the locale in Blockly.

For a full list of supported Blockly locales, see: [https://github.com/google/blockly/tree/master/msg/js](https://github.com/google/blockly/tree/master/msg/js)

## Docs

For more information about how to use Blockly, check out our
[devsite](https://developers.google.com/blockly/guides/overview).

## License

Apache 2.0

0 comments on commit f363252

Please sign in to comment.