babel-plugin-list-imports
Lists the files imported by a ESModule file.
Install
npm i babel-plugin-list-imports
Using
// Create the pluginconst importLister = // EventEmitter { plugin: [Plugin], state: [Set] } // Example code, demonstrates all recognized importsconst code = `// Normal default and named importsimport React from 'react'import { niceTool, helper as someHelper } from './some-utils.js' // Importing for side effects onlyimport 'side-effects.js' // Extension doesn't matterimport styles from './styles.css' // Importing all as namespaceimport * as namespaceImport from 'some-lib' // Exporting from sourceexport { default as something } from './source.js' // Exporting everything from a sourceexport * from './another-source.js' // Dynamic importsimport('dynamic') // Dynamic imports referencing an unchanged variableconst dynamicSrc = './tool.js'var unchangedDynamicSrc = '../path/to/import.js' import(dynamicSrc)import(unchangedDynamicSrc) // Non top-level dynamic importsdocument.getElementById('load-button').addEventListener('click', () => { import('string-literal') import(dynamicSrc) import(unchangedDynamicSrc)})` // Use the plugin // You don't need to wait for other plugins to run before accessing the imports// You can listen for the 'list' eventimportLister // This example does transformAsyncbabel