Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility for adding the root level verbatim at bottom instead of bundled up #1929

Open
Sairony opened this issue Oct 28, 2019 · 1 comment

Comments

@Sairony
Copy link

Sairony commented Oct 28, 2019

I'm creating a three.js loader, but there's a lot of sweet stuff from npm which I'd really like to leverage. Since I want as few dependencies as possible it would seem the best approach would be to use ES6 export / import, but that doesn't seem to be possible currently. I understand that the current system makes that hard, but it would seem like the generated format lends itself to just add a root level script at the bottom. The generated function would wrap up all the scripts as it currently does, but doesn't insert the code for the root script, instead it wraps the require function with the root module to module-id mappings which previously was inserted straight into the wrapping function, and returns that wrapped assigned to require. Super confusing, but essentially a bundle file would look like:

// Something which looks very close to what's currently being generated, but instead assigned to require
let require = (function () { function r(e, n, t) { ... },{},[]);
// Root level can now use require as per usual & create an exposed API which can be imported
let some_dep = require('some-dependency');
function foo_using_dep( arg ) { ... }
function bar_using_dep( arg ) { ... }
export { foo_using_dep, bar_using_dep };

Would there be any demand for such a feature or am I perhaps missing something? I'm far from an expert on neither javascript nor node.

@Sairony
Copy link
Author

Sairony commented Oct 29, 2019

I did a small example of hacking it together over here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant