如何使用base64禁用gulp编码图像?

问题描述

因此,在完成工作之后,我在css文件的base64中将图像编码为2.8mb((((

这是我的gulpfile:

const path = {
  stylus: {
    src: './src/stylus/**/*.styl',dest: './build/styles',},build: {
    dest: 'build/**'
  }
}

function stylusTask() {
  return src(path.stylus.src)
    .pipe(plumber())
    .pipe(stylus({
      use: nib(),import: ['nib'],compress: true
    }))
    .pipe(dest(path.stylus.dest))
}

解决方法

您可以将触控笔配置为仅对小于指定限制的图像进行编码。超过该限制的图片的网址将不会被修改。

在此示例中,仅对小于2000字节的图像进行编码:

function stylusTask() {
  return src(path.stylus.src)
    .pipe(plumber())
    .pipe(stylus({
      use: nib(),import: ['nib'],compress: true,define: {
        url: require('stylus').url({
          limit:2000
        })
      }       
    }))
    .pipe(dest(path.stylus.dest))
}

有关url函数的更多信息,请参见以下文档: https://stylus-lang.com/docs/functions.url.html

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...