如何用毛模板将图像重命名?
我的图像具有不同的标题:
- !test.png
- 1101.png
- 12345.jpg
- image3.jpg
- image4.jpg
- image5.jpg
- image5.jpg image6.jpg
- image7.jpg
- test_test.png test.png
- test.jpg test.jpg
- test2.png
我需要带有下一个标题的图像:
- 101。 png
- 102.png
- 103.jpg
- 104.png
- 105.png
- 106.jpg
- 107.jpg
- 108.jpg
- 109.jpg 109.jpg
- 110.jpg
- 111.png
示例:101.png =“ strong> 01.png “或“ 01.jpg ”,其中:
- “ 1 ”是可变的,当我输入Gulp命令时,我会在控制台中输入(
Gulp 1
) - “ 01..11.png ”(或“ 01..11.jpg ”)只是图像的名称按顺序
我有此代码,gulpfile.js:
import gulp from 'gulp';
import rename from 'gulp-rename';
import del from 'del';
const deleteImages = () => {
return del(['build',], {force:true});
}
const renameImages = () => {
return gulp.src('src/images/*.{jpg,jpeg,png,gif,wepb}')
.pipe(rename({
// code
}))
.pipe(gulp.dest('build'))
}
gulp.task('default', gulp.series(deleteImages, renameImages));
package.json:
{
"name": "gulp-rename-images",
"description": "Task for gulp",
"version": "0.0.1",
"license": "MIT",
"main": "gulpfile.js",
"type": "module",
"devDependencies": {
"gulp": "^4.0.2",
"gulp-rename": "^2.0.0",
"del": "^6.1.0"
}
}
我的结构:
I have images with different titles:
- !test.png
- 1101.png
- 12345.jpg
- image3.jpg
- image4.jpg
- image5.jpg
- image6.jpg
- image7.jpg
- test_test.png
- test.jpg
- test2.png
I need images with next titles:
- 101.png
- 102.png
- 103.jpg
- 104.png
- 105.png
- 106.jpg
- 107.jpg
- 108.jpg
- 109.jpg
- 110.jpg
- 111.png
Example: 101.png = "1" + "01.png" or "01.jpg", where:
- “1” is variable I enter in the console when I type the gulp command (
gulp 1
) - “01..11.png” (or “01..11.jpg”) are just the names of the images in ascending order
I have this code, gulpfile.js:
import gulp from 'gulp';
import rename from 'gulp-rename';
import del from 'del';
const deleteImages = () => {
return del(['build',], {force:true});
}
const renameImages = () => {
return gulp.src('src/images/*.{jpg,jpeg,png,gif,wepb}')
.pipe(rename({
// code
}))
.pipe(gulp.dest('build'))
}
gulp.task('default', gulp.series(deleteImages, renameImages));
package.json:
{
"name": "gulp-rename-images",
"description": "Task for gulp",
"version": "0.0.1",
"license": "MIT",
"main": "gulpfile.js",
"type": "module",
"devDependencies": {
"gulp": "^4.0.2",
"gulp-rename": "^2.0.0",
"del": "^6.1.0"
}
}
My structure:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我得到了此代码,Gulpfile.js:
packgage.json:
在我编写的控制台中:
有一个更漂亮的解决方案吗?
I got this code, gulpfile.js:
packgage.json:
In the console I write:
Is there a prettier solution?