This is in effect a partial rollback of PR #7822. This should solve issues encountered by users of bunders that don't support exports at all (e.g. browserify) as well as ones that don't support it in certain circumstances (e.g., when using webpack's resolve.alias configuration option to alias 'blockly' to 'node_modules/blockly', as we formerly did in most plugins, which causes webpack to ignore blockly's package.json entirely). Assumptions: - Such bundlers will _completely_ ignore the exports declaration. - The bundles are intended to be used in a browser—or at least not in node.js—so the core entrypoint never needs to route to core-node.js. This is reasonable since there's little reason to bundle code for node.js, and node.js has supported the exports clause since at least v12, considerably older than any version of node.js we officially support. - It suffices to provide only a CJS entrypoint (because we can only provide CJS or ESM, not both. (We could in future switch to providing only an ESM entrypoint instead, though.)
Blockly
Google's Blockly is a web-based, visual programming editor. Users can drag blocks together to build programs. All code is free and open source.
The source for this module is in the Blockly repo.
Example Usage
import * as Blockly from 'blockly/core';
Blockly.inject('blocklyDiv', {
...
})
Samples
For samples on how to integrate Blockly into your project, view the list of samples at blockly-samples.
Installation
You can install this package either via npm or unpkg.
unpkg
<script src="https://unpkg.com/blockly/blockly.min.js"></script>
When importing from unpkg, you can access imports from the global namespace.
// Access Blockly.
Blockly.thing;
// Access the default blocks.
Blockly.Blocks['block_type'];
// Access the javascript generator.
javascript.javascriptGenerator;
npm
npm install blockly
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.
// 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';
Requires
// 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');
Applying messages
Once you have the message files, you also need to apply them.
Blockly.setLocal(En);
For a full list of supported Blockly locales, see: https://github.com/google/blockly/tree/master/msg/js
Docs
For more information about how to use Blockly, check out our devsite.
License
Apache 2.0