let projectFolder= require('path').basename(dist);
это на второй строке, где сама переменная dist
? const server = done => {
browserSync.init({
server: {
baseDir: 'path to server root'
},
notify: false
});
done();
};
exports.server = server;
exports.default = series(server, parallel(css, allcss));
browserSync.stream()
с PHP сломается, и лучше использовать таску для этого, в которой будете вызывать browserSync.reload()
. + gulp-ttf2woff2@3.0.0
added 73 packages from 67 contributors and audited 438 packages in 14.272s
gulp.task('task-name', () => {
return gulp.src(...)
.pipe(gulp.dest(...));
});
build
меняете наgulp.task('build:vendor', gulp.parallel('vendorCss:build', 'vendorJs:build'));
gulp.task('build:sources', gulp.parallel('html:build', 'js:build', 'scss:build', 'css:build', 'fonts:build', 'image:build');
gulp.task('build', gulp.series('build:vendor', 'build:sources'));
gulp.task('clean', () => {
return del(path.clean);
});
gulp.task('webserver', (callback) => {
browserSync(config);
callback();
});
gulp.task('default', gulp.series('build', 'webserver', 'watch'));
const fs = require('fs');
const path = require('path');
const gulp = require('gulp');
const pipeIf = require('gulp-if');
const nunjucks = require('gulp-nunjucks');
const pretty = require('gulp-pretty-html');
const minify = require('gulp-htmlmin');
const replace = require('gulp-replace');
const sass = require('gulp-sass');
const sourcemaps = require('gulp-sourcemaps');
const autoprefixer = require('gulp-autoprefixer');
const clean = require('gulp-clean-css');
const rollup = require('rollup');
const resolve = require('@rollup/plugin-node-resolve');
const commonjs = require('@rollup/plugin-commonjs');
const babel = require('rollup-plugin-babel');
const { terser } = require('rollup-plugin-terser');
const image = require('gulp-image');
const clear = require('gulp-clean');
const browser = require('browser-sync').create();
const { argv } = require('yargs');
sass.compiler = require('node-sass');
const getFiles = dirname => {
const entries = fs.readdirSync(dirname);
const files = entries
.filter(entry => {
const stat = fs.statSync(path.join(dirname, entry));
return stat.isFile();
})
.reduce((accumulator, file) => {
const name = path.basename(file, path.extname(file));
accumulator[name] = path.join(dirname, file);
return accumulator;
}, {});
return files;
};
const scripts = getFiles('Sources/Scripts/');
gulp.task('server', (callback) => {
browser.init({
server: {
baseDir: 'Build'
},
ui: {
port: 8080
},
notify: false
});
callback();
});
gulp.task('reload', (callback) => {
browser.reload();
callback();
});
gulp.task('clear', () => {
return gulp.src('Build', { allowEmpty: true })
.pipe(clear({
force: true
}));
});
gulp.task('build:html', () => {
return gulp.src('Sources/**/*.html')
.pipe(nunjucks.compile())
.pipe(replace(/(\r\n|\r|\n)(\s+)?(\r\n|\r|\n)/gm, '\n'))
.pipe(pipeIf(argv.development, pretty({
indent_with_tabs: true,
extra_liners: []
})))
.pipe(pipeIf(argv.production, minify({
collapseWhitespace: true
})))
.pipe(gulp.dest(`Build/`));
});
gulp.task('build:sass', () => {
return gulp.src(['Sources/Styles/*.sass', 'Sources/Styles/*.scss'])
.pipe(pipeIf(argv.development, sourcemaps.init()))
.pipe(pipeIf(argv.development, sass({
indentWidth: 4,
outputStyle: 'expanded'
})))
.pipe(pipeIf(argv.production, sass()))
.pipe(autoprefixer({
cascade: false
}))
.pipe(pipeIf(argv.production, clean()))
.pipe(pipeIf(argv.development, sourcemaps.write('.')))
.pipe(gulp.dest('Build/Styles/'));
});
gulp.task('build:js', async (callback) => {
const bundle = await rollup.rollup({
input: scripts,
plugins: [
resolve(),
commonjs(),
babel({
exclude: 'node_modules/**',
presets: ['@babel/env']
}),
!!argv.production && terser({
keep_classnames: true
})
]
});
await bundle.write({
dir: 'Build/Scripts/',
format: 'esm',
chunkFileNames: '[name].js',
entryFileNames: '[name].js',
sourcemap: !!argv.development
});
callback();
});
gulp.task('build:images', () => {
return gulp.src(['Sources/Images/**/*.png', 'Sources/Images/**/*.jpg', 'Sources/Images/**/*.svg'])
.pipe(pipeIf(argv.production, image()))
.pipe(gulp.dest('Build/Images/'));
});
gulp.task('watch:html', () => {
gulp.watch(['Sources/**/*.html', 'Sources/**/*.njk'], gulp.series('build:html', 'reload'));
});
gulp.task('watch:sass', () => {
gulp.watch(['Sources/Styles/**/*.sass', 'Sources/Styles/**/*.scss'], gulp.series('build:sass', 'reload'));
});
gulp.task('watch:js', () => {
gulp.watch('Sources/Scripts/**/*.js', gulp.series('build:js', 'reload'));
});
gulp.task('watch:images', () => {
gulp.watch(['Sources/Images/**/*.png', 'Sources/Images/**/*.jpg', 'Sources/Images/**/*.svg'], gulp.series('build:images'));
});
gulp.task('watch:icons', () => {
gulp.watch('Sources/Icons/**/*.svg', gulp.series('build:html', 'reload'));
});
gulp.task('build', gulp.parallel('build:html', 'build:sass', 'build:js', 'build:images'));
gulp.task('watch', gulp.parallel('watch:html', 'watch:sass', 'watch:js', 'watch:images', 'watch:icons'));
gulp.task('default', gulp.series('clear', 'build', 'server', 'watch'));
gulp.task('build:html', () => {
return gulp.src('src/*.html')
.pipe(nunjucks.compile())
.pipe(gulp.dest('dist/'));
});
gulp.src('src/**/*.html')
.pipe(gulp.dest('build/'));
cmd
. Если gulp
установлен в devDependencies
, тогда через npm scripts
. gulp.src(...)
надо return gulp.src(...)
gulp.task('webserver', function () {
browserSync(config);
});
надо сделать так gulp.task('webserver', function (cb) {
browserSync(config);
cb();
});
const gulp = require('gulp');
const pipeIf = require('gulp-if');
const order = require('gulp-order');
const nunjucks = require('gulp-nunjucks');
const pretty = require('gulp-pretty-html');
const minify = require('gulp-htmlmin');
const replace = require('gulp-replace');
const sass = require('gulp-sass');
const sourcemaps = require('gulp-sourcemaps');
const autoprefixer = require('gulp-autoprefixer');
const clean = require('gulp-clean-css');
const babel = require('gulp-babel');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const image = require('gulp-image');
const clear = require('gulp-clean');
const browser = require('browser-sync').create();
const { argv } = require('yargs');
sass.compiler = require('node-sass');
gulp.task('server', (callback) => {
browser.init({
server: {
baseDir: 'Build'
},
ui: {
port: 8080
},
notify: false
});
callback();
});
gulp.task('reload', (callback) => {
browser.reload();
callback();
});
gulp.task('clear', () => {
return gulp.src('Build', { allowEmpty: true })
.pipe(clear({
force: true
}));
});
gulp.task('build:html', (callback) => {
return gulp.src('Sources/**/*.html')
.pipe(nunjucks.compile())
.pipe(replace(/(\r\n|\r|\n)(\s+)?(\r\n|\r|\n)/gm, '\n'))
.pipe(pipeIf(argv.development, pretty()))
.pipe(pipeIf(argv.production, minify({ collapseWhitespace: true })))
.pipe(gulp.dest(`Build/`));
});
gulp.task('build:sass', () => {
return gulp.src(['Sources/Styles/*.sass', 'Sources/Styles/*.scss'])
.pipe(pipeIf(argv.development, sourcemaps.init()))
.pipe(sass())
.pipe(autoprefixer({
cascade: false
}))
.pipe(pipeIf(argv.production, clean()))
.pipe(pipeIf(argv.development, sourcemaps.write('.')))
.pipe(gulp.dest('Build/Styles/'));
});
gulp.task('build:js', () => {
return gulp.src('Sources/Scripts/**/*.js')
.pipe(pipeIf(argv.development, sourcemaps.init()))
.pipe(order([
// Order for JS files
'*.js'
]))
.pipe(concat('main.js'))
.pipe(babel({
presets: ['@babel/env']
}))
.pipe(pipeIf(argv.production, uglify()))
.pipe(pipeIf(argv.development, sourcemaps.write('.')))
.pipe(gulp.dest('Build/Scripts/'));
});
gulp.task('build:images', () => {
return gulp.src(['Sources/Images/**/*.png', 'Sources/Images/**/*.jpg', 'Sources/Images/**/*.svg'])
.pipe(pipeIf(argv.production, image()))
.pipe(gulp.dest('Build/Images/'));
});
gulp.task('watch:html', () => {
gulp.watch(['Sources/**/*.html', 'Sources/**/*.njk'], gulp.series('build:html', 'reload'));
});
gulp.task('watch:sass', () => {
gulp.watch(['Sources/Styles/**/*.sass', 'Sources/Styles/**/*.scss'], gulp.series('build:sass', 'reload'));
});
gulp.task('watch:js', () => {
gulp.watch('Sources/Scripts/**/*.js', gulp.series('build:js', 'reload'));
});
gulp.task('watch:images', () => {
gulp.watch(['Sources/Images/**/*.png', 'Sources/Images/**/*.jpg', 'Sources/Images/**/*.svg'], gulp.series('build:images'));
});
gulp.task('build', gulp.parallel('build:html', 'build:sass', 'build:js', 'build:images'));
gulp.task('watch', gulp.parallel('watch:html', 'watch:sass', 'watch:js', 'watch:images'));
gulp.task('default', gulp.series('clear', 'build', 'server', 'watch'));