-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gulp: Modify 'svgsprite' task to support generation of multiple sprites
- Loading branch information
Showing
7 changed files
with
38 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,35 @@ | ||
import svgSprite from "gulp-svg-sprite"; | ||
import fs from "fs"; | ||
|
||
export const svgsprite = () => { | ||
return app.gulp.src(app.path.src.svgicons) | ||
.pipe(app.plugins.plumber()) | ||
.pipe(svgSprite({ | ||
mode: { | ||
stack: { | ||
sprite: "../icons/icons.svg", | ||
} | ||
} | ||
})) | ||
.pipe(app.gulp.dest(app.path.build.images)) | ||
.pipe(app.plugins.browsersync.stream()); | ||
export const svgsprite = async () => { | ||
// Get a list of folders in the source SVG icons directory | ||
const folders = fs.readdirSync(app.path.src.svgicons, {withFileTypes: true}) | ||
.filter(dirent => dirent.isDirectory()) | ||
.map(dirent => dirent.name); | ||
|
||
// Generate tasks for each folder to create SVG sprites | ||
const tasks = folders.map(folder => { | ||
const srcPath = `${app.path.src.svgicons}/${folder}/*.svg`; | ||
return new Promise ((resolve, reject) => { | ||
app.gulp.src(srcPath) | ||
.pipe(app.plugins.plumber()) | ||
.pipe(svgSprite({ | ||
mode: { | ||
stack: { | ||
sprite: `../svgsprite/${folder}.svg`, | ||
} | ||
} | ||
})) | ||
.pipe(app.gulp.dest(app.path.build.images)) | ||
.on('end', resolve) | ||
.on('error', reject); | ||
}); | ||
}); | ||
|
||
// Wait for all sprite generation tasks to complete | ||
return Promise.all(tasks).then(() => { | ||
// Refresh BrowserSync | ||
app.gulp.src(app.path.src.svgicons) | ||
.pipe(app.plugins.browsersync.stream()); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes