GithubHelp home page GithubHelp logo

image-web-loader's Introduction

image-web-loader

NPM version

一、简介

用于react-native for web的webpack 图片加载器

支持web端根据devicePixelRatio 来加载@1x @1.5x @2x @3x @4x

例如: require('image/a.jpg'); --> images/[email protected] .....

或者 require('image!x')

二、安装

npm install image-web-loader --save-dev

三、使用

Webpack config example:

const RequireImageXAssetPlugin  =require('image-web-loader').RequireImageXAssetPlugin;

module.exports = {
  plugins:[
    ....
    new RequireImageXAssetPlugin(path.resolve('assets/images'))
  ]
  module: {
    loaders: [
      {
        test: /\.(gif|jpeg|jpg|png|svg)$/,
        loader: 'image-web-loader!file-loader',
        query: {
          //true: require('a.jpg') 返回url 否则返回{width:xx,height:xx,uri:xxx}
          onlyWeb:false,
          progressive: true,
          optimizationLevel: 7,
          interlaced: false,
          pngquant: {
            quality: '65-90',
            speed: 4
          }
        }
      }
    ]
  }
}

Code example:

  // ---> {uri:'xxx/hello(@1x|@1.5x|@2x|@3x|@4x).png',width:xx,height:xx}
  require('./image/icon.png')  

  // --->  {uri:'xxx/assets/images/hello.(png|gif|jpg|ico|bmp)',width:xx,height:xx}
  require('image!hello')  

四、开源许可

基于 MIT License 开源,使用代码只需说明来源,或者引用 license.txt 即可。

image-web-loader's People

Stargazers

eJay avatar yinhf avatar  avatar  avatar beven91 avatar

Watchers

James Cloos avatar beven91 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.