0.2.0 • Published 5 years ago

babel-plugin-import-visitor v0.2.0

Weekly downloads
14
License
MIT
Repository
github
Last release
5 years ago

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