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

chore: modify readme about how we want people to acquire Blockly #7661

Merged
merged 2 commits into from
Dec 1, 2023
Merged
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
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it not be better to put this after the npm section—or even omit it entirely?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


```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.
BeksOmega marked this conversation as resolved.
Show resolved Hide resolved

```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