mirror of
https://github.com/tabler/tabler-icons.git
synced 2025-01-17 12:48:26 +01:00
icons sprite
This commit is contained in:
parent
62841aaacb
commit
0c0877269d
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 118 KiB After Width: | Height: | Size: 118 KiB |
33
gulpfile.js
33
gulpfile.js
@ -6,6 +6,33 @@ const gulp = require('gulp'),
|
||||
|
||||
|
||||
gulp.task('icons-sprite', function (cb) {
|
||||
glob("_site/icons/*.svg", {}, function (er, files) {
|
||||
|
||||
let svgContent = '';
|
||||
|
||||
files.forEach(function (file, i) {
|
||||
let name = path.basename(file, '.svg'),
|
||||
svgFile = fs.readFileSync(file),
|
||||
svgFileContent = svgFile.toString();
|
||||
|
||||
svgFileContent = svgFileContent
|
||||
.replace(/<svg[^>]+>/g, '')
|
||||
.replace(/<\/svg>/g, '')
|
||||
.replace(/\n+/g, '')
|
||||
.replace(/>\s+</g, '><')
|
||||
.trim();
|
||||
|
||||
svgContent += `<symbol id="${name}" viewBox="0 0 24 24">${svgFileContent}</symbol>`
|
||||
});
|
||||
|
||||
let svg = `<svg xmlns="http://www.w3.org/2000/svg"><defs>${svgContent}</defs></svg>`;
|
||||
|
||||
fs.writeFileSync('icons-sprite.svg', svg);
|
||||
cb();
|
||||
});
|
||||
});
|
||||
|
||||
gulp.task('icons-preview', function (cb) {
|
||||
const columnsCount = 17,
|
||||
padding = 29,
|
||||
paddingOuter = 5,
|
||||
@ -46,7 +73,7 @@ gulp.task('icons-sprite', function (cb) {
|
||||
|
||||
const svgContent = `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 ${width} ${height}" width="${width}" height="${height}" style="color: #354052"><rect x="0" y="0" width="${width}" height="${height}" fill="#fff"></rect>\n${svgContentSymbols}\n${svgContentIcons}\n</svg>`;
|
||||
|
||||
fs.writeFileSync('icons.svg', svgContent);
|
||||
fs.writeFileSync('demo/icons.svg', svgContent);
|
||||
cb();
|
||||
});
|
||||
});
|
||||
@ -82,7 +109,7 @@ gulp.task('icons-stroke', function (cb) {
|
||||
|
||||
const svgContent = `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 ${width} ${height}" width="${width}" height="${height}" style="color: #354052"><rect x="0" y="0" width="${width}" height="${height}" fill="#fff"></rect>\n${svgContentSymbols}\n${svgContentIcons}\n</svg>`;
|
||||
|
||||
fs.writeFileSync('icons-stroke.svg', svgContent);
|
||||
fs.writeFileSync('demo/icons-stroke.svg', svgContent);
|
||||
cb();
|
||||
});
|
||||
|
||||
@ -102,8 +129,6 @@ gulp.task('optimize', function (cb) {
|
||||
.replace(/\s+"/g, '"')
|
||||
.replace(/\n\n+/g, "\n");
|
||||
|
||||
console.log('file', file);
|
||||
|
||||
fs.writeFileSync(file, svgFileContent);
|
||||
});
|
||||
|
||||
|
1
icons-sprite.svg
Normal file
1
icons-sprite.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 55 KiB |
@ -14,7 +14,7 @@
|
||||
"main": "gulpfile.js",
|
||||
"scripts": {
|
||||
"optimize": "gulp optimize",
|
||||
"build": "gulp optimize && gulp build && gulp icons-sprite"
|
||||
"build": "gulp optimize && gulp build && gulp icons-preview && gulp icons-sprite"
|
||||
},
|
||||
"description": "",
|
||||
"devDependencies": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user