Essentially, it would allow for some form of importing only some exports
into a namespace. This would not affect the browser or environments like
node, but it would be a boon for module bundlers, such as webpack, rollup,
parcel, etc. It would allow you to specifically define which imports you
want, and the rest to be tree-shaken, and without any quirks of trying to
guess which imports from a
import * as d from"module";
are used.
It also would prevent the scope from getting cluttered. An example of where
this would be undesirable/annoying is the @material-ui/icons package on
npm. It exports many different icons, and an example of using them might be
as such:
import {
Wifi,
Accessibility,
Add,
Save,
Search
} from "@material-ui/icons";
import SearchBar from "./search";
// use them in some way
export default () => (
<>
<SearchBar />
<Wifi />
<Accessibility />
<Add />
<Save />
<Search />
</>
)
Alternatively, you could just import them * as icons, but then that
imports all of them and inflates the bundle size.
If this proposal were to be implemented, you could do something like
import {
Wifi,
Accessibility,
Add,
Save,
Search
} as icons from "@material-ui/icons";
import Search from "./search";
// use them in some way
export default () => (
<>
<Search />
<icons.Wifi />
<icons.Accessibility />
<icons.Add />
<icons.Save />
<icons.Search />
</>
)
and avoid the downsides.
This would also work for a library like lodash. It currently has ~320
utility functions, looking through their documentation, so importing * as _ would conflate the bundle immensely. With this proposal, issues like
that would be much less prevalent.
This is best introduced in a possible syntax:
```javascript
import { A, B, C } as d from "module";
```
Essentially, it would allow for some form of importing only some exports
into a namespace. This would not affect the browser or environments like
node, but it would be a boon for module bundlers, such as webpack, rollup,
parcel, etc. It would allow you to specifically define which imports you
want, and the rest to be tree-shaken, and without any quirks of trying to
guess which imports from a
```javascript
import * as d from "module";
```
are used.
It also would prevent the scope from getting cluttered. An example of where
this would be undesirable/annoying is the `@material-ui/icons` package on
npm. It exports many different icons, and an example of using them might be
as such:
```jsx
import {
Wifi,
Accessibility,
Add,
Save,
Search
} from "@material-ui/icons";
import SearchBar from "./search";
// use them in some way
export default () => (
<>
<SearchBar />
<Wifi />
<Accessibility />
<Add />
<Save />
<Search />
</>
)
```
Alternatively, you could just import them `* as icons`, but then that
imports all of them and inflates the bundle size.
If this proposal were to be implemented, you could do something like
```jsx
import {
Wifi,
Accessibility,
Add,
Save,
Search
} as icons from "@material-ui/icons";
import Search from "./search";
// use them in some way
export default () => (
<>
<Search />
<icons.Wifi />
<icons.Accessibility />
<icons.Add />
<icons.Save />
<icons.Search />
</>
)
```
and avoid the downsides.
This would also work for a library like lodash. It currently has ~320
utility functions, looking through their documentation, so importing `* as
_` would conflate the bundle immensely. With this proposal, issues like
that would be much less prevalent.
--
Noah Oxer
Student, Programmer, and Video Gamer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180623/03fd6c8d/attachment.html>
Nevermind, I was looking back through the mailing list and found this.
Nevermind, I was looking back through the mailing list and found [this](
https://esdiscuss.org/topic/import-foo-bar-as-obj-from-module).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180624/a1501ab5/attachment.html>
This is best introduced in a possible syntax:
import { A, B, C } as d from "module";
Essentially, it would allow for some form of importing only some exports into a namespace. This would not affect the browser or environments like node, but it would be a boon for module bundlers, such as webpack, rollup, parcel, etc. It would allow you to specifically define which imports you want, and the rest to be tree-shaken, and without any quirks of trying to guess which imports from a
import * as d from "module";
are used.
It also would prevent the scope from getting cluttered. An example of where this would be undesirable/annoying is the
@material-ui/icons
package on npm. It exports many different icons, and an example of using them might be as such:Alternatively, you could just import them
* as icons
, but then that imports all of them and inflates the bundle size.If this proposal were to be implemented, you could do something like
and avoid the downsides.
This would also work for a library like lodash. It currently has ~320 utility functions, looking through their documentation, so importing
* as _
would conflate the bundle immensely. With this proposal, issues like that would be much less prevalent.