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.

[FEATURE] Support rollup-style bundling

See original GitHub issue

Similar to the rollup this feature would combine all es6 modules with very minor modifications into a single module. In other words it’d flatten the modules. As with the rollup tool itself, this would make it easier to create export targets for sharing closure code between projects.

Consider the following set of modules:

File: parent.js

export class Parent {
  /**
   * @param {./utils/child.Child} child
   */
  constructor(child) {
     /** @const */
    this.child = child;
  }
}

File: utils/child.js

export class Child {
}

File: exports.js

import {Parent} from './src/parent.js';
import {Child} from './src/utils/child.js';

export {
  Parent,
  Child,
}

The closure_rollup tool with the exports.js as an input will produce the following single output module:

class Child {
}

class Parent {
  /**
   * @param {Child} child
   */
  constructor(child) {
     /** @const */
    this.child = child;
  }
}

export {
  Parent,
  Child,
}

In a nutshell, the closure_rollup --in exports.js --out out.js would do the following:

  1. Read all modules, analyzes imports, exports and closure type annotations. Construct the dependency graph.
  2. Order modules based on the dependency graph.
  3. Remove all import and export statements from all modules.
  4. Rewrite all types to be flat. E.g. {./utils/child.Child} -> {Child}.
  5. Keep all other whitespace/comments as intact as possible.
  6. Disambiguate duplicate names for top-level functions/classes.
  7. Possibly do a very minor tree shaking: any top-level function, class or type not referenced anywhere could be removed.
  8. Output all rewritten modules in order into a single module.
  9. Complete the output module with the exports from the provided exports.js.

This kind of tool could allow a single well-used Closure project to create numerous export targets that would be easily shareable in the Closure form for other Closure projects to use.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:15 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
dvoytenkocommented, Oct 23, 2018

@ChadKillingsworth Certainly. And as I mentioned above, we’re for now doing ok by executing rollup and regex-ing types. There are occasional errors and stuff though.

0reactions
ChadKillingsworthcommented, Oct 23, 2018

Bundling modules is definitely doable. Preserving type annotations is a big “maybe” (it’s there in the compiler, but it’s not perfect).

But preserving comments in general or expecting the output code to be perfectly human readable - that’s where things become problematic. That’s never been a goal of the compiler.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bundle Stylesheets and Add LiveReload With Rollup
Learn how to use the JavaScript bundler Rollup to process stylesheets using PostCSS and rebuild & reload files when changes are made in...
Read more >
rollup.js
rollup function receives an input options object as parameter and returns a Promise that resolves to a bundle object with various properties and...
Read more >
[Feature Request] Bundling with Rollup · Issue #642 - GitHub
I'm submitting a feature request Library Version: 1.0. ... Support to build Aurelia application with Rollup, ... I like ES6 code style.
Read more >
rollup-plugin-postcss - npm
0 only support rollup v2, and the extract path based on bundle root the location of the generated file outside the bundle directory...
Read more >
Bundle Up a JavaScript Project Using Rollup | by Jennifer Fu
Then we have the following generated dist/bundle.js : Lines 2-30 define a function to inject style sheets into the HTML file,. Line ...
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