Support ES6 modules in minimally-compiled bundles
See original GitHub issueFeature 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:
- Created 6 years ago
- Comments:5 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
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.
Support for this landed awhile ago.