A Babel plugin that works like Webpack's file-loader for server-side rendering (SSR) apps. It processes import/require statements for image files, copies them to an output directory, and replaces the source with a public URL. The current stable version is 2.0.0, which upgrades to Babel 7. It supports configurable naming patterns with hashing, custom public paths, output paths, and extensions. This plugin is maintained by sheerun and has 95% test coverage. Key differentiators: it does not require Webpack, works with any Node.js build pipeline, and is specifically designed for isomorphic/SSR apps where Webpack's file-loader cannot run.
npm install babel-plugin-file-loaderVerified import paths — ran on the pinned version, not inferred.
Configure babel-plugin-file-loader in .babelrc and use import to get a public URL for an image asset.
Upgrade to Babel 7 and ensure @babel/core is installed.
Use Webpack's file-loader or url-loader for client-side bundling; this plugin is for Node.js/SSR environments.
If you need the file to exist on disk, do not set outputPath to null.
Use '[hash].[ext]' not '[hash].png'.
Install the package: npm install babel-plugin-file-loader --save-dev. Ensure .babelrc uses "file-loader" (not "babel-plugin-file-loader") in the plugins array.
Upgrade to Babel 7 and @babel/core, or downgrade the plugin to version 1.x.
Add 'file-loader' to .babelrc plugins and ensure the extensions list includes the file type.