[FEATURE] Support rollup-style bundling
See original GitHub issueSimilar 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:
- Read all modules, analyzes imports, exports and closure type annotations. Construct the dependency graph.
- Order modules based on the dependency graph.
- Remove all
import
andexport
statements from all modules. - Rewrite all types to be flat. E.g.
{./utils/child.Child}
->{Child}
. - Keep all other whitespace/comments as intact as possible.
- Disambiguate duplicate names for top-level functions/classes.
- Possibly do a very minor tree shaking: any top-level function, class or type not referenced anywhere could be removed.
- Output all rewritten modules in order into a single module.
- 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:
- Created 5 years ago
- Comments:15 (11 by maintainers)
Top 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 >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
@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.
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.