diff options
Diffstat (limited to 'support/build/plugin-lodash-import-rename.js')
-rw-r--r-- | support/build/plugin-lodash-import-rename.js | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/support/build/plugin-lodash-import-rename.js b/support/build/plugin-lodash-import-rename.js new file mode 100644 index 0000000..6fe893b --- /dev/null +++ b/support/build/plugin-lodash-import-rename.js @@ -0,0 +1,24 @@ +import _ from 'lodash'; +import {dirname, sep} from 'path'; + +export default function() { + return { + visitor: { + + ImportDeclaration(path, mapping) { + let {node} = path; + let {value} = node.source; + + if (/\blodash\b/.test(value)) { + let f = mapping.file.opts.filename; + let dir = dirname(f).split(sep); + let relative = _.repeat('../', dir.length + 1); + + node.source.value = value.replace( + /\blodash\b/, + relative + 'node_modules/lodash-es'); + } + } + } + }; +} |