Ideally, the assembly should be such that the compiled files that will be given to the user are separate from the sources and can be safely deleted if necessary. In addition, this will allow you to do additional optimizations with the source files and not change the paths in the assembly.
Style Organization
In general, you have perfectly organized the assembly of styles: organized variable environments, added autofextruder. However, I would advise you to create two separate tasks for different environments in order to exclude additional conditions. In addition, it would be possible to add only 'dev/scss/main.scss' as paths and do @import in it to the rest of the files.
I would also advise you to add livereload() so that when you change files, your local server automatically loads all changes.
Also, I donβt understand how you would like the manipulations to be made only with modified files. If you compile all scss-files into one main.css , then operations will be performed on all main.css , after assembly. If you want the manipulations to be made only with the file that you are changing, you need to connect each of these files to the document and not to combine them during development.
Organization of pictures
I would advise you to keep the original images separately and transfer them to the build folder when compiled (let's call it public ). In addition to the usual transfer, it would be good to compress these pictures:
For example, pictures can be easily compressed without losing quality only by deleting exif-data. On a real site, you can reduce the size of images by an average of 70%, which on a modern site is approximately 4 MB. Example on gulp :
var gulp = require('gulp'), imagemin = require('gulp-imagemin'), imageminJR = require('imagemin-jpeg-recompress'), imageminSvgo = require('imagemin-svgo'); // Optimizing images gulp.task('imagemin', function() { gulp.src('./img/**/*') .pipe(imagemin([ imageminJR({ method: 'ms-ssim' }), imageminSvgo({ plugins: [ {removeViewBox: false} ] }) ])) .pipe(gulp.dest('./public/img/')) });
And for browsers that understand the lightweight webp format (format developed by Google), you can also make this version of the images:
var gulp = require('gulp'), webp = require('gulp-webp'); // Generate Webp gulp.task('webp', function() { gulp.src('./img/**/*') .pipe(webp()) .pipe(gulp.dest('./public/img/')) });
Font Organization
The same goes for fonts, but they only need to be moved to public :
// Replace fonts gulp.task('fonts', function () { gulp.src('./fonts/text-font/*') .pipe(gulp.dest('./public/fonts/')) });
Creating an icon font
It would be preferable to use the iconic font instead of pictures-sprites. And this method has several advantages:
- Lower font weight than sprite;
- CSS styling flexibility;
- Less weight CSS;
- Flexible size and unnecessary creation of versions for Retina-displays.
To generate an icon font, I would advise this combination:
// Generate icon font gulp.task('iconfont', function() { var fontName = 'icon-font', cssClass = 'i'; // ΠΡΡ
ΠΎΠ΄Π½ΡΠ΅ SVG-ΡΠ°ΠΉΠ»Ρ gulp.src(['./fonts/icon-font/*.svg']) .pipe(iconfontCss({ fontName: fontName, cssClass: cssClass, path: './styl/mixins/icon-font.styl', targetPath: '../../styl/components/font/icon-font.styl', fontPath: '../fonts/' })) .pipe(iconfont({ fontName: fontName, prependUnicode: true, normalize: true, formats: ['svg','ttf','woff','woff2'] })) .pipe(gulp.dest('./public/fonts/')); });
Bowls for styles that come from this line path: './styl/mixins/icon-font.styl' will look like this:
@font-face font-family "<%= fontName %>" src: url('<%= fontPath %><%= fontName %>.woff2') format('woff2'), url('<%= fontPath %><%= fontName %>.woff') format('woff'), url('<%= fontPath %><%= fontName %>.ttf') format('truetype'), url('<%= fontPath %><%= fontName %>.svg#<%= fontName %>') format('svg') [class*="i-"] position relative display inline-block width 1em height 1em &:before font 14px '<%= fontName %>' font-size inherit text-rendering auto speak none font-variant normal text-transform none color inherit position absolute top 50% left 50% transform translate(-50%, -50%) <% _.each(glyphs, function(glyph) { %> .<%= cssClass %>-<%= glyph.fileName %>:before content "\<%= glyph.codePoint %>" <% }); %>
After generating the font, all you need to do is connect the generated CSS to your site or ingress it to the main CSS file, and then use it like this:
<span class="i-<<ΠΈΠΌΡ ΠΈΡΡ
ΠΎΠ΄Π½ΠΎΠ³ΠΎ SVG-ΡΠ°ΠΉΠ»Π°>>"></span>