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

When packaging, copy the code and inline __DEV__ #1572

Closed
wants to merge 1 commit into from

Conversation

sophiebits
Copy link
Collaborator

Fixes #812.

Previously, this code

module.exports = moo();
function moo() { return __DEV__; }

would be transformed to

module.exports = moo();
function moo() { return "production" !== process.env.NODE_ENV; }

Now, it's transformed to:

if ("production" !== process.env.NODE_ENV) {
  var moo = function() { return true; };
  module.exports = moo();
} else {
  var moo = function() { return false; };
  module.exports = moo();
}

which reduces the getter cost to one test at require time instead of inline for every __DEV__ check, warning, and invariant.

The unminified build is about twice as large now (but it's about the same after gzipping) and the minified build is the same size.

@sophiebits
Copy link
Collaborator Author

cc @plievone @petehunt @benjamn

Fixes facebook#812.

Previously, this code

    module.exports = moo();
    function moo() { return __DEV__; }

would be transformed to

    module.exports = moo();
    function moo() { return "production" !== process.env.NODE_ENV; }

Now, it's transformed to:

    if ("production" !== process.env.NODE_ENV) {
      var moo = function() { return true; };
      module.exports = moo();
    } else {
      var moo = function() { return false; };
      module.exports = moo();
    }

which reduces the getter cost to one test at require time instead of inline for every `__DEV__` check, warning, and invariant.

The unminified build is about twice as large now (but it's about the same after gzipping) and the minified build is the same size.
@sophiebits
Copy link
Collaborator Author

(Looks like the tests don't pass yet, will fix.)

@zpao
Copy link
Member

zpao commented Jul 1, 2014

I don't like this. If we want to reduce the lookups, can we inline a __DEV__ = assignment at the top of every file and then leave __DEV__ alone everywhere?

@sophiebits
Copy link
Collaborator Author

Unfortunately uglifyjs isn't smart enough to strip out the DEV-only code then.

@zpao
Copy link
Member

zpao commented Aug 13, 2014

I very highly doubt we're going to do this so just going to close out

@zpao zpao closed this Aug 13, 2014
@sophiebits
Copy link
Collaborator Author

👍

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

Successfully merging this pull request may close these issues.

Server rendering is slower with npm react
2 participants