buffer-loader

raw JSON →
0.1.0 verified Sat Apr 25 auth: no javascript maintenance

A webpack loader that returns the content of a file as a Node.js Buffer. This package is at version 0.1.0, compatible with Node >=5.10 and webpack. It is adapted from binary-loader and provides a simple way to import binary files as Buffer objects in webpack bundles. It does not appear to have been updated since its initial release, and it is not widely used. Alternative loaders like raw-loader or file-loader may be more modern and maintained. It only works with CommonJS imports and is not compatible with ESM.

error Module not found: Error: Can't resolve 'buffer-loader'
cause buffer-loader is not installed or not in node_modules.
fix
Run npm install buffer-loader --save-dev
gotcha buffer-loader is not compatible with ESM imports directly; use CommonJS require with the loader prefix.
fix Use const content = require('buffer-loader!./file.bin'); instead of import.
gotcha buffer-loader may not work with webpack 4+ if not configured properly; it is an older loader.
fix Consider using raw-loader for newer webpack versions: { test: /\.bin$/, use: 'raw-loader' }.
npm install buffer-loader
yarn add buffer-loader
pnpm add buffer-loader

Configures webpack to use buffer-loader for .bin files, then imports a binary file as a Buffer.

// webpack.config.js
module.exports = {
  module: {
    rules: [
      {
        test: /\.bin$/,
        use: 'buffer-loader'
      }
    ]
  }
};

// In a module
const fileContent = require('buffer-loader!./file.bin');
console.log(fileContent); // <Buffer ...>