Функция fontsStyle не работает, взято с видео https://www.youtube.com/watch?v=jU88mLuLWlk&list=WL&index=2&t=4964s
fonts.js
export const fontsStyle = () => {
//Файл стилей подключения шрифтов
let fontsFile = `${app.path.srcFolder}/scss/fonts.scss`;
//Проверяем, существуют ли файлы шрифтов
fs.readdir(app.path.build.fonts, function(err, fontsFiles){
if(fontsFiles) {
//Проверяем, существует ли файл стилей для подключения шрифтов
if(!fs.existsSync(fontsFile)) {
//Если файла нет, создаём его
fs.writeFile(fontsFile, '', cb);
let newFileOnly;
for (var i = 0; i < fontsFiles.length; i++) {
//Записываем подключения шрифтов в файл стилей
let fontFileName = fontsFiles[i].split('.')[0];
if (newFileOnly !== fontFileName) {
let fontName = fontFileName.split('-')[0] ? fontFileName.split('-')[0] : fontFileName;
let fontWeight = fontFileName.split('-')[1] ? fontFileName.split('-')[1] : fontFileName;
if (fontWeight.toLowerCase() === 'thin') {
fontWeight = 100;
} else if (fontWeight.toLowerCase() === 'extralight') {
fontWeight = 200;
} else if (fontWeight.toLowerCase() === 'light') {
fontWeight = 300;
} else if (fontWeight.toLowerCase() === 'medium') {
fontWeight = 500;
} else if (fontWeight.toLowerCase() === 'semibold') {
fontWeight = 600;
} else if (fontWeight.toLowerCase() === 'bold') {
fontWeight = 700;
} else if (fontWeight.toLowerCase() === 'extrabold' || fontWeight.toLowerCase() === 'heavy') {
fontWeight = 800;
} else if (fontWeight.toLowerCase() === 'black') {
fontWeight = 900;
} else {
fontWeight = 400;
}
fs.appendFile(fontsFile, `@font-face{\n\tfont-family: ${fontName};\n\tfont-display: swap;\n\tsrc: url("../fonts/${fontFileName}.woff2") format("woff2"), url("../fonts/${fontFileName}.woff") format("woff");\n\tfont-weight: ${fontWeight};\n\tfont-style: normal;\n}\r\n`, cb);
newFileOnly = fontFileName;
}
}
} else {
//Если файл есть, выводим сообщение
console.log("Файл scss/fonts.scss уже существует. Для обновления файла нужно его удалить!");
}
}
});
return app.gulp.src(`${app.path.srcFolder}`);
function cb() { }
}
gulpfile.js
import gulp from "gulp";
import { path } from "./gulp/config/path.js";
import { plugins } from "./gulp/config/plugins.js";
global.app = {
path: path,
gulp: gulp,
plugins: plugins,
}
import { copy } from "./gulp/tasks/copy.js";
import { reset } from "./gulp/tasks/reset.js";
import { html } from "./gulp/tasks/html.js";
import { server } from "./gulp/tasks/server.js";
import { scss } from "./gulp/tasks/scss.js";
import { js } from "./gulp/tasks/js.js";
import { images } from "./gulp/tasks/images.js";
import { otfToTtf, ttfToWoff, fontsStyle } from "./gulp/tasks/fonts.js";
function watcher(){
gulp.watch(path.watch.files, copy)
gulp.watch(path.watch.html, html)
gulp.watch(path.watch.scss, scss)
gulp.watch(path.watch.js, js)
gulp.watch(path.watch.images, images)
}
const fonts = gulp.series(otfToTtf, ttfToWoff, fontsStyle);
const mainTasks = gulp.series(fonts, gulp.parallel(copy, html, scss, js, images));
const dev = gulp.series(reset, mainTasks, gulp.parallel(watcher, server));
gulp.task('default', dev);
Ошибка в терминале:
Error: File not found with singular glob: C:/Users/Пользователь/Desktop/gulp/undefined (if this was purposeful, use
allowEmpty
option.
Источник: Stack Overflow на русском