fix: loading messages from script tags. (#6184)

* fix: loading messages in the browser

* chore: fix comment

* fix: change unwrapped message files to write to a new object, rather than Blockly.Msg

* fix: fixup exports

* fix: PR comments

* fix: change to use for-in loop

* fix: ES6 compatibility and formatting
This commit is contained in:
Beka Westberg
2022-06-13 14:13:54 -07:00
parent 24a808d54e
commit 188ba985cc
3 changed files with 27 additions and 12 deletions

View File

@@ -29,12 +29,12 @@ const TEMPLATE_DIR = 'scripts/package/templates';
* @param {string} namespace The export namespace.
* @param {Array<Object>} dependencies An array of dependencies to inject.
*/
function packageUMD(namespace, dependencies) {
function packageUMD(namespace, dependencies, template = 'umd.template') {
return gulp.umd({
dependencies: function () { return dependencies; },
namespace: function () { return namespace; },
exports: function () { return namespace; },
template: path.join(TEMPLATE_DIR, 'umd.template')
template: path.join(TEMPLATE_DIR, template)
});
};
@@ -321,13 +321,10 @@ function packageLocales() {
// Remove references to goog.provide and goog.require.
return gulp.src(`${BUILD_DIR}/msg/js/*.js`)
.pipe(gulp.replace(/goog\.[^\n]+/g, ''))
.pipe(gulp.insert.prepend(`
var Blockly = {};Blockly.Msg={};`))
.pipe(packageUMD('Blockly.Msg', [{
name: 'Blockly',
amd: '../core',
cjs: '../core',
}]))
.pipe(packageUMD(
'Blockly.Msg',
[{name: 'Blockly'}],
'umd-msg.template'))
.pipe(gulp.dest(`${RELEASE_DIR}/msg`));
};