Socket
Socket
Sign inDemoInstall

esm-loader-images

Package Overview
Dependencies
115
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    esm-loader-images

Chainable ESModule Loader for Images


Version published
Weekly downloads
449
decreased by-46.1%
Maintainers
1
Install size
4.60 MB
Created
Weekly downloads
 

Readme

Source

esm-loader-images

Node.js ESModule Loader for Images.

Supported image filename extensions:

  • Binary (imported as filename text string):
    • .apng .avif .gif .ico .jpg .jpeg .jfif .pjpeg .pjp .png .webp
  • Text (imported as full text content string):
    • .svg

Warning! Using experimental Node.js features and flags, API will likely change. This may be helpful for development and testing, but should not be used in production.

Usage

npm install --save-dev esm-loader-images

We want to import a .svg (or other image) file with Node.js:

<!-- image.svg -->
<svg>
  <circle cx="50" cy="50" r="50" fill="red" />
</svg>
// index.js
import image from './image.svg'

console.log(image)
// "<svg><circle ... /></svg>"

Standalone

# node >= 20.7
cat << EOF > ./register.js
import { register } from 'node:module'
register('esm-loader-images', import.meta.url)
EOF
NODE_OPTIONS="--import ./register.js" node index.js

# node < 20.7
NODE_OPTIONS="--loader esm-loader-images" node index.js

Chainable

This loader can be configured, and chained with other loaders, using node-esm-loader.

npm install --save-dev node-esm-loader
// .loaderrc.js
export default {
  loaders: ['esm-loader-images'],
}
# node >= 20.7
NODE_OPTIONS="--import node-esm-loader/register" node index.js

# node < 20.7
NODE_OPTIONS="--loader node-esm-loader" node index.js
Options
Debug
// .loaderrc.js
export default {
  loaders: [
    {
      loader: 'esm-loader-images',
      options: {
        debug: true,
      },
    },
  ],
}

License

MIT

Keywords

FAQs

Last updated on 01 Nov 2023

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc