babel-plugin-import-visitor

Visit all import sources in Babel

MIT License

Downloads
21
Stars
10
Committers
1

babel-plugin-import-visitor Travis npm package

This Babel plugin gives you a way to visit all the import nodes (and export from) in a JavaScript program. It's useful for building your own plugins where you would like to somehow manipulate the import sources.

For example, if you wanted to change all imports of react to https://unpkg.com/react?module, you could do the following:

import babel from '@babel/core';
import importVisitor from 'babel-plugin-import-visitor';

const options = {
  // ...
  plugins: [
    importVisitor(node => {
      if (node.value === 'react') {
        node.value = 'https://unpkg.com/react?module';
      }
    })
  ]
};

babel.transform(code, options);

License

MIT