[[oktatas:web:nodejs:gulp|< Gulp]]
====== Gulp - Szerver indítása ======
* **Szerző:** Sallai András
* Copyright (c) 2022, Sallai András
* Licenc: [[https://creativecommons.org/licenses/by-sa/4.0/|CC BY-SA 4.0]]
* Web: https://szit.hu
===== Szerver feladat =====
A child_process használatához nem kell telepíteni semmit.
...
const exec = require('child_process').exec;
...
function server() {
exec('npm start', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
}
...
exports.server = server;
===== Teljes gulpfile.js =====
const { src, dest, series } = require('gulp');
const exec = require('child_process').exec;
const cleanCss = require('gulp-clean-css');
const rename = require('gulp-rename');
const uglify = require('gulp-uglify');
function createHTML(cb) {
src(['src/*.html'])
.pipe(dest('public'));
cb();
}
function createCSS(cb) {
src(['src/css/*.css'])
.pipe(cleanCss())
.pipe(rename({extname: ".min.css"}))
.pipe(dest('public/css'));
cb();
}
function createJS(cb) {
src(['src/js/*.js'])
.pipe(uglify())
.pipe(rename({extname: ".min.js"}))
.pipe(dest('public/js'));
cb();
}
function server() {
exec('npm start', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
}
exports.html = createHTML;
exports.css = createCSS;
exports.js = createJS;
exports.server = server;
exports.default = series(createHTML, createCSS, createJS, server);
===== A lite-server beállítása =====
{
"server": ["src"],
"port": 8000
}
{
...
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "lite-server"
},
...
}