Node's Package Magician

    react-native-imagemin-asset-plugin

    1.4.0 • Public • Published

    react-native-imagemin-asset-plugin

    semantic-release LICENSE npm-version npm

    简体中文

    Metro Asset plugin for compressing images in React Native.

    Minify PNG, JPG, JPEG, GIF, SVG and WEBP images with imagemin

    example

    Usage

    Step 1: Install

    yarn add -D react-native-imagemin-asset-plugin

    or

    npm install --save-dev react-native-imagemin-asset-plugin

    Step 2: Configure metro.config.js

    Add react-native-imagemin-asset-plugin to the list of assetPlugins in your metro.config.js file under the transformer section.

    For example;

    module.exports = {
      transformer: {
        getTransformOptions: async () => ({
          transform: {
            experimentalImportSupport: false,
            inlineRequires: false,
          },
        }),
        assetPlugins: ['react-native-imagemin-asset-plugin'],
      },
    };

    Configuration

    You can configure the plugin behaviour through the optional imageminAssetPlugin field in your metro.config.js file under the transformer section.

    For example;

    module.exports = {
      transformer: {
        // ...
        assetPlugins: ['react-native-imagemin-asset-plugin'],
        imageminAssetPlugin: {
          imageminDir: '.compressed-images',
          pngquant: {
            quality: [0.6, 0.8],
          },
          mozjpeg: {
            quality: 60,
          },
        },
      },
    };
    Option Description Reference
    imageminDir Name of directory to store compressed images. Default: .shrunken
    giflossy Compress GIF images https://github.com/imagemin/imagemin-giflossy
    gifsicle Compress GIF images https://github.com/imagemin/imagemin-gifsicle
    jpegtran Compress JPEG images https://github.com/imagemin/imagemin-jpegtran
    mozjpeg Compress JPEG images https://github.com/imagemin/imagemin-mozjpeg
    optipng Compress PNG images https://github.com/imagemin/imagemin-optipng
    pngquant Compress PNG images https://github.com/imagemin/imagemin-pngquant
    svgo Compress SVG images https://github.com/imagemin/imagemin-svgo
    webp Compress JPG & PNG images into WEBP https://github.com/imagemin/imagemin-webp

    LICENSE

    MIT

    Other

    ...

    Install

    npm i react-native-imagemin-asset-plugin

    DownloadsWeekly Downloads

    7

    Version

    1.4.0

    License

    MIT

    Unpacked Size

    9.15 kB

    Total Files

    4

    Last publish

    Collaborators

    • chengbo