npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

postcss-auto-imgmq

v1.1.1

Published

Automatically insert media query for image

Downloads

2

Readme

postcss-auto-imgmq

根据图片名或图片路径自动添加媒体查询到样式表

常见场景

  • retina屏高清图片自动适配
  • 根据屏幕尺寸替换背景图片
  • 其他媒体查询条件相关图片样式自动生成

如何使用

1.从npm安装

npm install -D postcss-auto-imgmq

2.添加到postcss插件列表(以webpack为例)

const imgmq = require('postcss-auto-imgmq');

// ...

module: {
    rules:[
        {
            test: /\.css$/,
            use: [{
                loader: 'style-loader'
            },{
                loader: 'css-loader'
            },{
                loader: 'postcss-loader',
                options: {
                    plugins:[
                        imgmq({
                            // options
                        })
                    ]
                }
            }]
        }
    ]
}

3.将高清图片放入静态资源目录

以默认配置为例,在ball.png的当前所在目录将高清图片命名为[email protected]
或 在ball.png的当前所在目录新建名为3x的文件夹,放入与之同名的高清图片
媒体查询即会自动生成并插入

注:原图与适配图必须都存在才会生成样式

Eg: 原css代码

.ball .one .imgBox {
    width: 50%;
    background-image: url("./img/ball_1.png");
}

.ball .two .imgBox {
    width: 100%;
    background-image: url("./img/ball_2.png");
}

插件处理后

.ball .one .imgBox {
    width: 50%;
    background-image: url("./img/ball_1.png");
}

.ball .two .imgBox {
    width: 100%;
    background-image: url("./img/ball_2.png");
}

@media (-webkit-min-device-pixel-ratio:3),(min-device-pixel-ratio:3) {
.ball .one .imgBox {
    background-image: url('img/[email protected]');
}
.ball .two .imgBox {
    background-image: url('img/3x/ball_2.png');
}
}

options

  • detectPostfix

自动检测的图片名后缀,默认值@3x
设置为nullfalse或空字符串''则不根据图片名后缀自动检测

  • detectDirname

自动检测的目录名,默认值3x
设置为nullfalse或空字符串''则不根据目录名自动检测

  • mediaQuery

自动插入的媒体查询条件,默认值(-webkit-min-device-pixel-ratio:3),(min-device-pixel-ratio:3)

注意事项

尚未在除win10之外的平台上运行过