question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support ES6 modules in minimally-compiled bundles

See original GitHub issue

Feature request: it seems possible that ES6 modules would work in minimally compiled bundles (e.g. compile=False js_binary rules) by converting them to goog.module form. Something like:

// foo.js
import {bar} from './bar.js';

export const foo = bar + 10;

might be transformed to:

// bundle.js
goog.loadModule('module$foo', function() {
  const {bar} = goog.require('$module$bar');
  
  exports.foo = bar + 10;
});

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
jplaistedcommented, Sep 11, 2017

Already working on this! Note that goog.loadModule accepts one argument currently; the module definition function. We’re planning on adding a second argument, the path of the module. And we’re planning on support for relative, path goog.requires in a goog.module that resolve against the path that was passed in as the argument. Mostly this is for interop between goog and ES6 modules, but it makes this bundled case nice as well.

So your above example would be transformed to

goog.loadModule(function() {
  const {bar} = goog.require('./bar.js');
  
  exports.foo = bar + 10;
}, '/foo.js');

bar.js would also be similarly transformed and its exports would be registered under its path (/bar.js). So when the goog.require(‘./bar.js’) is called, it resolves to /bar.js, and the exports can be retrieved.

This will be done path based rather than symbol based since we need a similar mechanism for the debug loading case, and this way we don’t need to rewrite any paths at all (either to full paths or substitutes for symbols), which would require unnecessary rewriting of goog modules in the debug loading case.

0reactions
jplaistedcommented, Jun 12, 2018

Support for this landed awhile ago.

Read more comments on GitHub >

github_iconTop Results From Across the Web

16. Modules - Exploring JS
ES6 is the first time that JavaScript has built-in modules. ES6 modules are stored in files. ... ES6 modules support cyclic dependencies automatically....
Read more >
ES6 browser support: is it time to rethink bundling? - Contentful
The new setup using native supported ES6 modules. Now that we have the “traditional bundle” for all the browsers that don't support ES6...
Read more >
ES6 In Depth: Modules - the Web developer blog
An ES6 module is a file containing JS code. There's no special module keyword; a module mostly reads just like a script.
Read more >
ES6 Modules and How to Use Import and Export in JavaScript
The ES2015 (ES6) edition of the JavaScript standard gives us native support for modules with the import and export syntax.
Read more >
Demystifying Code Bundling with JavaScript Modules
Spanning the gap between ES5 and ES6 required tools that converted, “transpiled”, ES6 code to serve it to browsers that only supported ES5....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found