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: Do not wrap imports in the identity function un-necessarily #3001

Closed
lukeapage opened this issue Sep 16, 2016 · 8 comments
Closed

Comments

@lukeapage
Copy link
Contributor

I'm submitting a feature request

Webpack version:
2.1.0-beta.22

Please tell us about your environment:
Windows 8

Current behavior:

// test.js
import {a} from './a.js';
a();

// a.js
export function a() {
   console.log('a');
}

output:

/***/ function(module, exports, __webpack_require__) {

"use strict";
/* harmony export (immutable) */ exports["a"] = a;
function a() {
    console.log('a');
}

/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {

"use strict";
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__a__ = __webpack_require__(0);


__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__a__["a"])();

/***/ }

Expected/desired behavior:

__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__a__["a"])();

becomes

__WEBPACK_IMPORTED_MODULE_0__a__["a"]();
  • What is the motivation / use case for changing the behavior?

Smaller bundle size, less executed code. Because the function being imported does not reference this, it does not need to be wrapped in identity function. Because actually most exported functions will not reference this.

Further if I have this code

import * as a from './a';
a.a();

then identity is not added, meaning the exports object is provided to the function when I call it - so that is inconsistent.

@sokra
Copy link
Member

sokra commented Sep 18, 2016

Yep, I'm also a bit annoyed by this. We will do many optimizations after webpack 2. We want to get to a stable working version before optimizing. The cost is small: r.i(b.a)() compared to b.a().

@webpack-bot
Copy link
Contributor

This issue had no activity for at least half a year.

It's subject to automatic issue closing if there is no activity in the next 15 days.

@lukeapage
Copy link
Contributor Author

I'd like to keep this open. If someone could give me some pointers to where to start, I might be able find some time for a pr. Spent a while searching but it's really hard to guess the best approach and find the right code to modify.

@lukeapage
Copy link
Contributor Author

@sokra would you be able to help with a where to start?

@sokra
Copy link
Member

sokra commented Aug 11, 2017

Scope Hoisting should eliminate most of these.

I'm currently not sure how to solve this.

@lukeapage
Copy link
Contributor Author

Good point. I will check how many of these are left after hoisting.

@webpack-bot
Copy link
Contributor

This issue had no activity for at least half a year.

It's subject to automatic issue closing if there is no activity in the next 15 days.

@webpack-bot
Copy link
Contributor

Issue was closed because of inactivity.

If you think this is still a valid issue, please file a new issue with additional information.

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

No branches or pull requests

4 participants