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

[feature request] inline all imports into a single file #1681

Closed
samccone opened this issue Jun 4, 2015 · 14 comments
Closed

[feature request] inline all imports into a single file #1681

samccone opened this issue Jun 4, 2015 · 14 comments
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@samccone
Copy link
Contributor

samccone commented Jun 4, 2015

Use case:

You create a library/tool that has dependencies.
You want to distribute your library in a UMD format (and have it work in the browser without a user having to use something like system.js to polyfill "require")

Current solution:

Using browserify to do the inlining work or create a custom build system to support this.

Ideal solution:

A flag to enable this joining inside of babel.

Why does this belong in core?

If you support exporting to UMD, then for it to be truly universal inlining the dependencies is essential.

Thanks 👾

@sebmck
Copy link
Contributor

sebmck commented Jun 4, 2015

This was discussed in #495 but closed since there were bigger things to worry about then. Now seems like a good time to resurrect it. cc @zertosh who I know is interested in integrating Babel more tightly into module bundling 😄

@gaearon
Copy link
Member

gaearon commented Jun 4, 2015

Why should Babel support this? Don't Browserify and Webpack solve this problem well with an ecosystem of plugins, servers, watchers and other dev tools?

(Not being snarky. Genuinely wondering.)

@zertosh
Copy link
Member

zertosh commented Jun 4, 2015

@gaearon browserify and webpack kinda solved it, but having multiple source->ast->source steps really limits what you can do. Erasing the division between packaging and transformation makes sense. Think about it, packaging is just another transformation that just so happens to span multiple files.

@samccone
Copy link
Contributor Author

samccone commented Jun 4, 2015

@gaearon I agree 100%

Why should Babel support this? Don't Browserify and Webpack solve this problem well with an ecosystem of plugins, servers, watchers and other dev tools?

If we wanted to take this further as @sebmck and I talked about in meatspace:

I think module formatters and the watcher should be dropped from babel... but until we do the great strip down of the library into a just a code "transformer", this enhancement does have a place.

🐳 💿 🌾

@calidion
Copy link

+1
browserify or webpack are a seemingly poor tools for packing.
like java's obfuscation, packing and uglifying into a file is very important for both front end and server back.

@cesarandreu
Copy link
Contributor

I'm not sure of the benefits of having babel generated bundles. I let Webpack handle all of this functionality, and babel is just another transformer in the pipeline.

Why are browserify or webpack bad tools for packing?

@engma
Copy link

engma commented Jun 24, 2015

+1 it would be really awesome to just use this in babelJS, since it would be a one step conversion

@zbraniecki
Copy link
Contributor

I wrote a very minimalistic es6 bundler as a plugin for babel.

You can find the source code here: https://gist.github.com/zbraniecki/649e0390d57ac353494d
(it requires a small patch to babel that landed here: #1951 and should be in the next release)

It looks like this:

It turns sth like this:
./src/lib/core.js:

export function foo() {
}

./src/runtime/web/index.js

import { foo } from '../../lib/core';

into:

'use strict';

(function (global) {
  const modules = new Map();
  const moduleCache = new Map();

  function getModule(id) {
    if (!moduleCache.has(id)) {
      moduleCache.set(id, modules.get(id).call(global))
    }
    return moduleCache.get(id);
  }

  modules.set('lib/core', function () {
    function foo() {
    }
    return { foo };
  });

  modules.set('runtime/web/index', function () {
    const { foo } = getModule('lib/core');
  });
})(this);

It allows us to remove webpack from the toolchain (which is important because webpack cannot work on not-transpiled es6 code) and gives us a very readable output because the modules look as close to the original files as possible.

I'd be happy to release our bundler as a separate module if there's interest from people.

@eventualbuddha
Copy link
Member

I'm willing to bet this wouldn't handle all cases well. What happens with
cycles? Would something like Esperanto's bundler work for you?
On Wed, Jul 8, 2015 at 2:04 PM Zibi Braniecki notifications@github.com
wrote:

I wrote a very minimalistic es6 bundler as a plugin for babel.

You can find the source code here:
https://gist.github.com/zbraniecki/649e0390d57ac353494d
(it requires a small patch to babel that landed here: #1951
#1951 and should be in the next
release)

It looks like this:

It turns sth like this:
./src/lib/core.js:

export function foo() {
}

./src/runtime/web/index.js

import { foo } from '../../lib/core';

into:

'use strict';

(function (global) {
const modules = new Map();
const moduleCache = new Map();

function getModule(id) {
if (!moduleCache.has(id)) {
moduleCache.set(id, modules.get(id).call(global))
}
return moduleCache.get(id);
}

modules.set('lib/core', function () {
function foo() {
}
return { foo };
});

modules.set('runtime/web/index', function () {
const { foo } = getModule('lib/core');
});
})(this);

It allows us to remove webpack from the toolchain (which is important
because webpack cannot work on not-transpiled es6 code) and gives us a very
readable output because the modules look as close to the original files as
possible.

I'd be happy to release our bundler as a separate module if there's
interest from people.


Reply to this email directly or view it on GitHub
#1681 (comment).

@zbraniecki
Copy link
Contributor

No support for cycles yet. Didn't need so far

@jamesplease
Copy link
Member

@samccone, clarifying question. Do you mean all dependencies including third party libraries? Or just 'internal' dependencies?

In other words, if my point of entry file has:

import $ from 'jquery';
import utils from './utils';

Would you want the flag to bundle up both jQuery and utils, or just utils?

@samccone
Copy link
Contributor Author

both @jmeas :)

@jamesplease
Copy link
Member

k, cool. 👍

@sebmck
Copy link
Contributor

sebmck commented Sep 1, 2015

Closing this and marking it as revisit for something to look into in the future. I'll delegate this to rollup for the timebeing.

@sebmck sebmck closed this as completed Sep 1, 2015
@sebmck sebmck added the revisit label Sep 1, 2015
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jul 12, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jul 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

10 participants