diff --git a/README.md b/README.md index ab676806..1d7ae2b5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# babel-loader -[![NPM Status](https://img.shields.io/npm/v/babel-loader.svg?style=flat)](https://www.npmjs.com/package/babel-loader) -[![Build Status](https://travis-ci.org/babel/babel-loader.svg?branch=master)](https://travis-ci.org/babel/babel-loader) +# babel-loader +[![NPM Status](https://img.shields.io/npm/v/babel-loader.svg?style=flat)](https://www.npmjs.com/package/babel-loader) +[![Build Status](https://travis-ci.org/babel/babel-loader.svg?branch=master)](https://travis-ci.org/babel/babel-loader) [![Build Status](https://ci.appveyor.com/api/projects/status/vgtpr2i5bykgyuqo/branch/master?svg=true)](https://ci.appveyor.com/project/danez/babel-loader/branch/master) [![codecov](https://codecov.io/gh/babel/babel-loader/branch/master/graph/badge.svg)](https://codecov.io/gh/babel/babel-loader) > Babel is a compiler for writing next generation JavaScript. @@ -89,6 +89,8 @@ module: { * `babelrc`: Default `true`. When `false`, will ignore `.babelrc` files (except those referenced by the `extends` option). + * `forceEnv`: Default will resolve BABEL_ENV then NODE_ENV. Allow you to override BABEL_ENV/NODE_ENV at the loader level. Useful for isomorphic applications with different babel configuration for client and server. + __Note:__ The `sourceMap` option is ignored, instead sourceMaps are automatically enabled when webpack is configured to use them (via the `devtool` config option). ## Troubleshooting diff --git a/src/index.js b/src/index.js index 3c5caf81..57948bf8 100644 --- a/src/index.js +++ b/src/index.js @@ -88,10 +88,12 @@ module.exports = function(source, inputSourceMap) { babelrc: exists(userOptions.babelrc) ? read(userOptions.babelrc) : resolveRc(path.dirname(filename)), - env: process.env.BABEL_ENV || process.env.NODE_ENV, + env: userOptions.forceEnv || process.env.BABEL_ENV || process.env.NODE_ENV, }), }; + delete userOptions.forceEnv; + const options = assign({}, defaultOptions, userOptions); if (userOptions.sourceMap === undefined) {