mjackson / babel-plugin-import-visitor

Visit all import sources in Babel

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

Visit all import sources in Babel

License:MIT License


Languages

Language:JavaScript 100.0%