打包图片的常见使用
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'))
);
}