Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
binary-base64-loader
Advanced tools
A loader for webpack that allows importing binary files as a String
A webpack loader that allows loading binary files as Base64 encoded strings.
Based on https://github.com/webpack-contrib/raw-loader
Install binary-base64-loader
:
$ npm install binary-base64-loader --save-dev
After that you can load files with specific extensions using webpack config as usual, for example:
webpack.config.js
// webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.bin$/i,
use: 'binary-base64-loader',
},
],
},
};
Then you can import the content of binary files with the given extension as Base64 encoded strings:
import bigAsset from './asset.bin';
// bigAsset will equal to 'WW91IGp1c3QgbG9zdCBUSEUgR0FNRSE=...
Most probably though you will want to use the loader inline, without registering specific extensions in the webpack config. For example:
import fontBinary from '!!binary-base64-loader!./funkyicons.ttf';
(The !!
prefix is not obligatory but probably you will need it to remove other loaders from the chain which could apply based on the webpack config)
To make the inline use work under Typescript add this to a Typescript definition file in your project (*.d.ts
, for example shims-vue.d.ts
):
declare module "!!binary-base64-loader!*" {
const content: string;
export default content;
}
Name | Type | Default | Description |
---|---|---|---|
esModule | {Boolean} | true | Uses ES modules syntax |
esModule
Type: Boolean
Default: true
By default, binary-base64-loader
generates JS modules that use the ES modules syntax.
There are some cases in which using ES modules is beneficial, like in the case of module concatenation and tree shaking.
You can enable a CommonJS module syntax using:
webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.bin$/i,
use: [
{
loader: 'binary-base64-loader',
options: {
esModule: false,
},
},
],
},
],
},
};
FAQs
A loader for webpack that allows importing binary files as a String
The npm package binary-base64-loader receives a total of 5,140 weekly downloads. As such, binary-base64-loader popularity was classified as popular.
We found that binary-base64-loader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.