Giter VIP home page Giter VIP logo

rollup-plugin-img's Introduction

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.
  • hash: Optional. a boolean value to indicate wheather to generate a hash string in file name(default false).

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

rollup-plugin-img's People

Contributors

alwaysonlinetxm avatar

Watchers

James Cloos avatar David Beale avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.