Skip to content
This repository has been archived by the owner on Apr 9, 2020. It is now read-only.

Add configuration for which transforms to run in production #7

Closed
gaearon opened this issue Sep 3, 2015 · 6 comments
Closed

Add configuration for which transforms to run in production #7

gaearon opened this issue Sep 3, 2015 · 6 comments

Comments

@gaearon
Copy link
Owner

gaearon commented Sep 3, 2015

Right now, transforms have to include special code to opt out of production effect. Even if they are no-ops, the code to call them is still generated, and any imports are still imported.

I think we should change this behavior:

  • All transforms should be turned off by default in production
  • Transform configuration may have an opt-in production: true which enables it in production
  • If there are no transforms enabled in production, we don't generate the component records and related code, as there is nothing to consume it
@gaearon
Copy link
Owner Author

gaearon commented Sep 3, 2015

Maybe we can solve this on Babel configuration level.
See env option in .babelrc: https://babeljs.io/docs/usage/babelrc/

@gaearon
Copy link
Owner Author

gaearon commented Sep 3, 2015

For example, a config could look like this:

{
  "stage": 0,
  "env": {
    "development": {
      "plugins": ["react-transform"],
      "extra": {
        "react-transform": [{
          "target": "react-transform-webpack-hmr",
          "imports": ["react"],
          "locals": ["module"]
        }, {
          "target": "react-transform-catch-errors",
          "imports": ["react", "redbox-react"]
        }]
      }    
    }
  }
}

You'd need to compile your project with NODE_ENV=production, for example:

NODE_ENV=production webpack --config webpack.config.production.js

(Unix)

or

set NODE_ENV=production && webpack --config webpack.config.production.js

(Windows)

@chrishoage
Copy link

I can confirm that using the babel env option works exactly as expected. No changes required at all.

@amccloud
Copy link

amccloud commented Sep 4, 2015

using env works for me too

@ameensol
Copy link

here to confirm redundantly that babel env also worked for me

@gaearon
Copy link
Owner Author

gaearon commented Sep 23, 2015

Closing, as it's not our responsibility.

Users can either use .babelrc or put the configuration into query option (it can be an object!) of Webpack babel-loader configuration.

@gaearon gaearon closed this as completed Sep 23, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants