Skip to content

Commit

Permalink
fix: Use babelrc file relative to cwd.
Browse files Browse the repository at this point in the history
closes: babel#166
  • Loading branch information
briandipalma committed Apr 5, 2016
1 parent e66dc0d commit 43a3c7b
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,37 @@ module.exports = function(source, inputSourceMap) {
var globalOptions = this.options.babel || {};
var loaderOptions = loaderUtils.parseQuery(this.query);
var userOptions = assign({}, globalOptions, loaderOptions);
var babelrc = exists(userOptions.babelrc) ?
read(userOptions.babelrc) :
resolveRc(process.cwd());
var babelrcOpts = JSON.parse(babelrc || '{}');
var defaultOptions = {
inputSourceMap: inputSourceMap,
sourceRoot: process.cwd(),
filename: filename,
cacheIdentifier: JSON.stringify({
'babel-loader': pkg.version,
'babel-core': babel.version,
babelrc: exists(userOptions.babelrc) ?
read(userOptions.babelrc) :
resolveRc(process.cwd()),
babelrc: babelrc,
env: process.env.BABEL_ENV || process.env.NODE_ENV,
}),
};

var options = assign({}, defaultOptions, userOptions);
if (babelrcOpts.plugins) {
babelrcOpts.plugins = babelrcOpts.plugins.map(function(plugin) {
return require.resolve('babel-plugin-' + plugin) ||
require.resolve(plugin);
});
}

if (babelrcOpts.presets) {
babelrcOpts.presets = babelrcOpts.presets.map(function(preset) {
return require.resolve('babel-preset-' + preset) ||
require.resolve(preset);
});
}

var options = assign({}, defaultOptions, babelrcOpts, userOptions);

if (userOptions.sourceMap === undefined) {
options.sourceMap = this.sourceMap;
Expand Down

0 comments on commit 43a3c7b

Please sign in to comment.