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

webpack-image-loader

v0.1.2

Published

处理css以及spa页面中的本地图片引用

Downloads

464

Readme

webpack-image-loader

目前支持自动识别的图片格式有:jpg、png、gif。 基于webpack4,处理css以及spa页面中的本地图片引用。 自带转base64编码,基于imagemin的图片压缩功能。

警告: 图片相对路径必须是中文路径。 现在支持的图片有 jpg png gif svg icon

如何配置该loader的options项?

  • root 默认是:/images 设置相对于输出目录的根目录。 例如: root:'/image',打包目录是dist,那么生成的目录就是 /dist/image
  • name 默认是:/[hash:12].[ext] 设置生成文件的名称,基于interpolateName生成。 可使用以下变量: [path][name][ext][hash]等等扩展参数,更多参考 假设使用[hash][name].[ext],./home/image/header.png => e4da3b7fbbce2345d7772b0674a318d5header.png
  • base64 设置需要转换的图片大小。【在0.1.0该版本中不在支持】 比如设置为3000,那么表示小于3kb的图片会自动转换为base64编码
  • imagemin 图片压缩配置。【在0.1.0该版本中不在支持】 以下是支持压缩的图片格式:
  • [x] imagemin-jpegtran , 对应参数imageminJpegtran
  • [x] imagemin-pngquant , 对应参数imageminPngquant
  • [x] imagemin-mozjpeg , 对应参数imageminMozjpeg 例如: { imageminJpegtran:{}, imageminPngquant:{quality:[0.75,.9]}, imageminMozjpeg:{quality:75} }

如何在webpack中配置,这里以webpack4为例

注意,在使用该loader的时候建议放在执行顺序最前面。

    rules:[
        {
            test:/\.css$/,
            use:[
                "style-loader","css-loader",
                {
                    loader:"webpack-image-loader",
                    options:{
                        root:'/image',
                        name:'[hash].[ext]',
                        base64:30000,
                        imagemin:{
                            imageminPngquant:{
                                quality:[0.75,.9]
                            }
                        }
                    }
                }
            ]
        },
        {
            test:/\.(ts|tsx)$/,
            loader:["ts-loader",{loader:"webpack-image-loader",options:{root:'/html'}}]
        }
    ]

当然,你也可以使用默认配置

    use:["style-loader","css-loader","webpack-image-loader"]

新增了自动检出插件

该插件功能将避免未更改的图片资源参与构建,有助于大型多入口项目进行快速构建。

    const webpackImageLoaderPlugins = require("webpack-image-loader/compiler");

	new webpackImageLoaderPlugins({
		fileName: 'img-lock.txt'
	})