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

A bundle should be a module #4202

Closed
paleo opened this issue Feb 4, 2017 · 4 comments
Closed

A bundle should be a module #4202

paleo opened this issue Feb 4, 2017 · 4 comments

Comments

@paleo
Copy link

paleo commented Feb 4, 2017

What is the current behavior?

A bundle generated by Webpack cannot be used as a module.

What is the expected behavior?

We should have the ability to make bundled modules.

For example:

// libA.js
export let a = "Hello"

// libB.js
export let b = "World"

// entry.js
import {a} from "./libA"
import {b} from "./libB"

export let message = `${a}, ${b}!`

Then the webpack bundling would generate a single file:

// bundle.js
/*
 * Here all the usual Webpack stuff,
 * then:
 */
export {message}

The modules libA and libB are not accessible from outside the bundle. But I suggest that all exported members of entry (the entry point defined in webpack.config.js) could be exported by the bundle.

Use cases

Native support for ES6 modules is coming in browsers. We should be able to use Webpack bundles as native modules.

Even now. I currently generates my bundled libraries without Webpack by concatenating files and append exports because I didn't find how to export something from a bundle.

@timse
Copy link
Member

timse commented Feb 5, 2017

how should those bundles be consumed if the browser does not have native support for es6? :)

@paleo
Copy link
Author

paleo commented Feb 5, 2017

By Webpack or SystemJS.

Notice: An exportFormat option could be provided, with values in: 'ES6' | 'AMD' | 'CommonJS' | 'UMD'.

@gbakernet
Copy link

@paleo There is libraryTarget config option that does what you are suggesting a exportFormat could do. amd, commonjs and umd are supported.

I see there is some discussion around supporting es2015 modules (formerly es6). #2933.

@paleo
Copy link
Author

paleo commented Feb 6, 2017

@gbakernet Thank you. :)

@paleo paleo closed this as completed Feb 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants