babel-plugin-import-visitor

0.2.0 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i babel-plugin-import-visitor

Weekly Downloads

8

Version

0.2.0

License

MIT

Unpacked Size

6.05 kB

Total Files

5

Last publish

Collaborators

  • mjackson