Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-inline-import-data-uri

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-inline-import-data-uri

Babel plugin to make raw files importable as base64 encoded data URI strings.

  • 0.1.2
  • npm
  • Socket score

Version published
Weekly downloads
3.7K
decreased by-3.39%
Maintainers
1
Weekly downloads
 
Created
Source

Babel Inline Import Data URI

Babel plugin to add the opportunity to use import file content as DataURI.

Examples

// server.js
import logo from './logo.svg';

// Will print "data:image/svg+xml;base64,PD94bWwgdmVyc2lv...4KPC9zdmc+';"
console.log(logo);

Install

npm install babel-plugin-inline-import-data-uri --save-dev

Use

Add a .babelrc file and write:

{
  "plugins": [
    "inline-import-data-uri"
  ]
}

or pass the plugin with the plugins-flag on CLI

babel-node myfile.js --plugins inline-import-data-uri

By default, Babel-Inline-Import is compatible with the following file extensions:

  • .svg
  • .png

Customize

If you want to enable different file extensions, you can define them in your .babelrc file

{
  "plugins": [
    ["babel-plugin-inline-import", {
      "extensions": [
        ".html",
        ".jpg"
      ]
    }]
  ]
}

How it works

It inserts the content of the imported file directly into the importing file encoded as Data URI, assigning it to a variable with the same identifier of the import statement, thus replacing the import statement and the file path by its resulting content.

Caveats

Babel does not track dependency between imported and importing files after the transformation is made. Therefore, you need to change the importing file in order to see your changes in the imported file spread. To overcome this:

Also make sure that your task runner is watching for changes in the imported file as well. You can see it working here.

Credits

This project is based on babel-plugin-inline-import.

Keywords

FAQs

Package last updated on 13 Aug 2017

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc