diff --git a/scripts/gulpfiles/build_tasks.js b/scripts/gulpfiles/build_tasks.js index 5b9213a76..4178b04bf 100644 --- a/scripts/gulpfiles/build_tasks.js +++ b/scripts/gulpfiles/build_tasks.js @@ -333,6 +333,12 @@ function chunkWrapper(chunk) { const browserDeps = chunk.dependencies.map(d => `root.${d.exports}`).join(', '); const factoryParams = chunk.dependencies.map(d => d.importAs).join(', '); + + // Note that when loading in a browser the base of the exported path + // (e.g. Blockly.blocks.all - see issue #5932) might not exist + // before factory has been executed, so calling factory() and + // assigning the result are done in separate statements to ensure + // they are sequenced correctly. return `// Do not edit this file; automatically generated. /* eslint-disable */ @@ -342,7 +348,8 @@ function chunkWrapper(chunk) { } else if (typeof exports === 'object') { // Node.js module.exports = factory(${cjsDeps}); } else { // Browser - root.${chunk.exports} = factory(${browserDeps}); + var factoryExports = factory(${browserDeps}); + root.${chunk.exports} = factoryExports; } }(this, function(${factoryParams}) { ${chunk.factoryPreamble || FACTORY_PREAMBLE}