webpack binary-loader
raw JSON → 0.0.1 verified Sat Apr 25 auth: no javascript deprecated
A webpack loader that returns a file's content as a binary string. Adapted from raw-loader. Version 0.0.1, no recent updates. Key differentiators: allows importing binary files as strings without base64 encoding. No active maintenance, use raw-loader or file-loader with encoding options instead.
Common errors
error Module not found: Error: Can't resolve 'binary-loader' in /path ↓
cause Missing npm install or local path issue.
fix
Run 'npm install binary-loader' and ensure it's in node_modules.
error Module build failed: loader 'binary' not found ↓
cause Loader name typo.
fix
Use 'binary-loader' or 'binary!./file.bin' (with exclamation) in require.
Warnings
deprecated This package is no longer maintained and has limited functionality. ↓
fix Use raw-loader or file-loader instead.
breaking Works only with legacy webpack 1/2; incompatible with webpack 4+ without additional configuration. ↓
fix Use webpack 4+ compatible alternatives.
gotcha Output is a binary string (not Buffer or ArrayBuffer), which may cause issues with binary data handling. ↓
fix Consider using raw-loader or file-loader for proper binary handling.
Install
npm install binary-loader yarn add binary-loader pnpm add binary-loader Imports
- default wrong
import content from 'binary!./file.bin'correctrequire('binary!./file.bin') - loader function wrong
export default function(content) {}correctmodule.exports = function(content) {}
Quickstart
// webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.bin$/,
use: 'binary-loader'
}
]
}
};
// app.js
var binaryData = require('./file.bin');
console.log(binaryData); // binary string of file content