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

rollup-plugin-img

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rollup-plugin-img

import image files with rollup

  • 1.0.6
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.8K
decreased by-21.6%
Maintainers
1
Weekly downloads
 
Created
Source

rollup-plugin-img

Import image files with rollup. Let you import images just like what you do with webpack in your React code!

Installation

yarn add --dev rollup-plugin-img

or

npm install -D rollup-plugin-img

Usage

In the rollup.config.js:

import image from 'rollup-plugin-img';

export default {
  entry: 'src/index.js',
  dest: 'dist/bundle.js',
  plugins: [
    image({
      limit: 10000
    })
  ]
};

and in your React code:

import img from 'path/image.png';

  ...
  render() {
    return <img src={ img } />;
  }
  ...

Options

You can pass an option to the image() just like above, and there are some options:

  • exclude & include: Optional. like other rollup plugins. Details
  • output: Required. the dest path of output image files. The first directory of dest will be handled as the base output directory(where the html file will be, usually).
  • extensions: Optional. a regular expression for the extensions of image files.
  • limit: Optional. the limit(byte) of the file size. A file will be transformed into base64 string when it doesn't exceeded the limit, otherwise, it will be copyed to the dest path.

demo:

  ...
  image({
    output: `${distPath}/images`, // default the root
    extensions: /\.(png|jpg|jpeg|gif|svg)$/, // support png|jpg|jpeg|gif|svg, and it's alse the default value
    limit: 8192,  // default 8192(8k)
    exclude: 'node_modules/**'
  })
  ...

License

MIT

Keywords

FAQs

Package last updated on 21 Jul 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