Load files into memory for parsing and traversal with Babylon/Babel. Version 2.0.0 is the latest stable release, published as part of the babel-multi-file project. It provides async and sync methods to resolve file paths from import declarations and load parsed File objects, enabling multi-file Babel plugin analysis. Key differentiators: integrates directly with Babel's visitor pattern and File representation, offering low-level control over file resolution and parsing.
npm install babel-file-loaderVerified import paths — ran on the pinned version, not inferred.
Shows how to use loadImportSync inside a Babel plugin visitor to load and parse the file referenced by an import declaration.
Upgrade to v2.0.0 and adapt code to use new sync/async naming (e.g., loadImportSync instead of callback-based loadImport).
Use dynamic import() inside CommonJS, or switch to ES module context. For Babel plugins, ensure your plugin file uses .mjs or "type": "module" in package.json.
Wrap calls in try/catch blocks to prevent Babel plugin from crashing.
Consider using @babel/traverse and @babel/core's programmatic API for multi-file analysis.
Prefer sync variants (loadImportSync) for use inside Babel visitors; async functions may not work as expected.
Use dynamic import: const { loadImportSync } = await import('babel-file-loader'); or switch your project to ES modules.Rename the file to .mjs or add "type": "module" to your package.json.
Use file.path.traverse({...}) where file is the return value of loadImportSync.Install babylon: npm install babylon@latest
No dependency data recorded yet.