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

Setup BABEL_ENV for Webpack2 via loader #283

Closed
nodkz opened this issue Aug 11, 2016 · 12 comments · Fixed by #368
Closed

Setup BABEL_ENV for Webpack2 via loader #283

nodkz opened this issue Aug 11, 2016 · 12 comments · Fixed by #368

Comments

@nodkz
Copy link

nodkz commented Aug 11, 2016

Need the ability to pass the desired environment name to babel via babel-loader.

I have such .babelrc:

{
  "presets": [
    "es2015",
    "stage-0",
    "react"
  ],
  "env": {
    "webpack2": {
      "presets": [
        ["es2015", {"modules": false}],
        "stage-0",
        "react"
      ],
    }
  }
}

I'm starting webpack via run script which written with es6 modules. But if I start script with BABEL_ENV=webpack2 then it requires rewriting all scripts to commonjs style.

Furthermore I should rewrite all app, cause use Relay with babelRelayPlugin.

So the better way to use Webpack2 with passing env value via babel-loader settings.

@sonicoder86
Copy link

the es2015 preset setup you are using is missing the loose property set to true

@sonicoder86
Copy link

look at my comment in this issue #282

@nodkz
Copy link
Author

nodkz commented Aug 23, 2016

@BlackSonic what does loose property means? This question worried me about 2 months, but all tries to found answer failed.

@danez
Copy link
Member

danez commented Aug 23, 2016

Can you please explain what your problem is? I'm sorry but I didn't get exactly what you are saying.

If you set BABEL_ENV to webpack2 it should pick up the correct babel config from you .babelrc

@nodkz
Copy link
Author

nodkz commented Aug 23, 2016

@danez sorry, my fault.

I'm using webpack bundler with multiple configs (server, client, admin, ...).
Right now BABEL_ENV is common for a build-script that starts webpack and for babel-loader. So will be cool if babel-loader has an additional option that can allow choosing another babel environment rather than provided via BABEL_ENV.

Lookup behavior for babel-loader:

  • env option in the query
  • BABEL_ENV
  • NODE_ENV

PS. This is a very cool feature for the transition period when we want to use webpack2, but V8 does not supports import. So I'll run build script with ENV with {"modules": "commonjs"} needed for proper work of some plugins and set ENV with {"modules": false} in runtime for babel-loader that transforms source files for tree shaking.

@sonicoder86
Copy link

@nodkz
Copy link
Author

nodkz commented Aug 23, 2016

@BlackSonic many thanks!

Catch the loose mode keywords from your link.

...many transforms have a “loose” mode which drops some spec behavior in favor of simpler and more performant generated code.

Example of how initial ES6 code generated to normal and loose code

@moimael
Copy link
Contributor

moimael commented Sep 7, 2016

I'm in the exact same situation, is there a workaround in the meantime ?

@saiichihashimoto
Copy link

+1

@moimael
Copy link
Contributor

moimael commented Sep 22, 2016

Are maintainers ok on principle to add an env query parameter to babel-loader ?

@danez
Copy link
Member

danez commented Sep 22, 2016

👍

@teonik
Copy link

teonik commented Dec 30, 2016

+1...This behaviour certainly is useful.To get something similar to what @nodkz is talking about i create a separate babelrc and reference it via the 'extends' query option.Not very clean IMHO 'cause my babel configuration is split in two files, one for the build tools and one for webpack bundling.But gets the job done.Did anyone else tackle this problem differently?

moimael pushed a commit to moimael/babel-loader that referenced this issue Feb 2, 2017
fix babel#283

Signed-off-by: Maël Lavault <[email protected]>
moimael pushed a commit to moimael/babel-loader that referenced this issue Feb 2, 2017
fix babel#283

Signed-off-by: Maël Lavault <[email protected]>
@moimael moimael mentioned this issue Feb 2, 2017
4 tasks
moimael pushed a commit to moimael/babel-loader that referenced this issue Feb 2, 2017
fix babel#283

Signed-off-by: Maël Lavault <[email protected]>
moimael pushed a commit to moimael/babel-loader that referenced this issue Feb 2, 2017
fix babel#283

Signed-off-by: Maël Lavault <[email protected]>
@danez danez closed this as completed in #368 Feb 7, 2017
danez pushed a commit that referenced this issue Feb 7, 2017
fix #283

Signed-off-by: Maël Lavault <[email protected]>
This issue was closed.
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 a pull request may close this issue.

6 participants