babel-plugin-webpack-alias
Advanced tools
Comparing version 1.8.4 to 1.9.0
@@ -31,4 +31,4 @@ 'use strict'; | ||
// exit if there's no alias config | ||
if (!conf.resolve || !conf.resolve.alias) { | ||
// exit if there's no alias config and the config is not an array | ||
if (!(conf.resolve && conf.resolve.alias) && !Array.isArray(conf)) { | ||
return; | ||
@@ -38,5 +38,49 @@ } | ||
// Get the webpack alias config | ||
const aliasConf = conf.resolve.alias; | ||
const extensionsConf = conf.resolve.extensions && conf.resolve.extensions.length ? conf.resolve.extensions : null; | ||
let aliasConf; | ||
let extensionsConf; | ||
if (Array.isArray(conf)) { | ||
// the exported webpack config is an array ... | ||
// (i.e., the project is using webpack's multicompile feature) ... | ||
// reduce the configs to a single alias object | ||
aliasConf = conf.reduce((prev, curr) => { | ||
const next = Object.assign({}, prev); | ||
if (curr.resolve && curr.resolve.alias) { | ||
Object.assign(next, curr.resolve.alias); | ||
} | ||
return next; | ||
}, {}); | ||
// if the object is empty, bail | ||
if (!Object.keys(aliasConf).length) { | ||
return; | ||
} | ||
// reduce the configs to a single extensions array | ||
extensionsConf = conf.reduce((prev, curr) => { | ||
const next = [].concat(prev); | ||
if (curr.resolve && curr.resolve.extensions && curr.resolve.extensions.length) { | ||
curr.resolve.extensions.forEach(ext => { | ||
if (next.indexOf(ext) === -1) { | ||
next.push(ext); | ||
} | ||
}); | ||
} | ||
return next; | ||
}, []); | ||
if (!extensionsConf.length) { | ||
extensionsConf = null; | ||
} | ||
} else { | ||
// the exported webpack config is a single object... | ||
// use it's resolve.alias property | ||
aliasConf = conf.resolve.alias; | ||
// use it's resolve.extensions property, if available | ||
extensionsConf = conf.resolve.extensions && conf.resolve.extensions.length ? conf.resolve.extensions : null; | ||
} | ||
var _path$node = path.node; | ||
@@ -43,0 +87,0 @@ const calleeName = _path$node.callee.name; |
{ | ||
"version": "1.8.4", | ||
"version": "1.9.0", | ||
"name": "babel-plugin-webpack-alias", | ||
@@ -4,0 +4,0 @@ "description": "babel 6 plugin which allows to use webpack aliases", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15166
174