[email protected] 不能用来找我

打包图片的常见使用
在这里插入图片描述

package.json
最新版本都是使用 ES6 模块,如果本地使用的require()的话,两个用法不一致导致会出现问题,不如都使用ES6模块,只需要在package.json 添加"type": "module"即可。

{
    
    
  "name": "img",
  "version": "1.0.0",
  "description": "",
  "main": "gulpfile.js",
  "scripts": {
    
    
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "type": "module",
  "devDependencies": {
    
    
    "gulp": "^4.0.2",
    "gulp-image": "^6.3.1",
    "gulp-imagemin": "^8.0.0"
  }
}

gulpfile.js

import gulp from 'gulp';
import imagemin from 'gulp-imagemin';

export default () => {
    
    
    return (
        gulp.src('src/images/*')
        .pipe(imagemin())
        .pipe(gulp.dest('dist/images'))
    );
}

猜你喜欢

转载自blog.csdn.net/qq_41961239/article/details/122402116