1.0.1 • Published 8 years ago

babel-plugin-inline-import-data-uri v1.0.1

Weekly downloads
15,076
License
MIT
Repository
-
Last release
8 years ago

Babel Inline Import Data URI

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

Examples

import logo from './logo.svg';
import background from './background.png';

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

class MyComponent extends React.Component
{
  render() {
    return (
      <div style={{background: `url(${background})`}}>
        <img src={logo}/>
      </div>;
    );
  }
}

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": [
    ["inline-import-data-uri", {
      "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.

Credits

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

babel-preset-twreporter-reactdw-mx-packing-tools@cliffdotai/atomic-toolsonlinex-ui-tools@infinitebrahmanuniverse/nolb-babel-plugin-i@everything-registry/sub-chunk-1202gm-toolwillow-build-toolswallb-toolswdxantdjxt-tools@om-tlh/x-tools@om-tlh/xbee-toolsflexiflowkunsam-toolstu-toolstjs-component-libraryumi-plugin-libraryumi-plugin-library-test@aiot-design/basic@aiot-design/components@aiot-design/formily@aiot-design/utils@bs-design/tools@chrissong/xmd-tools@clinia/design-tools@cliffdotai/tools@9188/doso@51yzone/tools@digigov/cli-build@digigov/dev@conradoluiz/next-with-typescriptzcomyach.open.ui-toolsyuso-toolszf-toolszs-ui-toolwebxtunion-cli-testunion-toolvc-toolznd-tools@pengfuxiao1992/ka-tools@fishx/component-tools@greendeck/atomic-tools@huoli/tools@fle-ui/tools@gingkoo/pandora-cli@infra-fe/tools@lingxiteam/cli@lovemelovemydog/tools@luban-cli/cli-lib-service@lotus-ui/tools@nicedu/tools@jdthfe/ivory@om-tlh/bee-toolsmkui-toolsosp-lit-commonparsec-adminsdgoo-toolsrt-ui-toolsray-pack-toolkitrcm-toolsrc-gulprollup-toolkitppx-toolsr-compile-toolssky-scriptsskripto-plugingio-rewireincisive-edge-toolsgui-toolshrsass-toolshive-bee-design-toolslfbuilder-uileona-uilyj-designlushu-antd-tools@webtanzhi/rope-tools@thfe/ivory@thscom/mars-cli@uniubi/tools@uni-ubi/tools@uno-design/tools@zalastax/nolb-babel-plugin-i@symph/ant-plus@taror/toolsaiot-designantd-goo-toolsantd-toolsantd-tools-extraantd-tools-ideallifebubaibohe-uidw-neit-toolsdw-mx-toolsdw-neit-antd-toolsedge-toolsemptyd-toolsgalaxy-tools
1.0.1

8 years ago

1.0.0

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago