Thursday, 4 May 2017

Gulp and node not working - they return nothing or error?

I have installed node, npm and gulp:

$ sudo apt update
$ sudo apt install nodejs
$ sudo apt install npm
$ sudo npm install gulp -g

But when I run gulp to execute my gulpfile.js, it returns nothing. And when I want to check the version of my gulp: $ gulp -v it returns nothing too.

What is going on? What have I missed?

This is my gulpfile:

var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');
var livereload = require('gulp-livereload');

// CSS compilation.
var concat = require('gulp-concat');
var cleanCSS = require('gulp-clean-css');
var concatCss = require('gulp-concat-css'); // optional

// Optional enhancement:
gulp.task('apply-prod-environment', function() {
    process.stdout.write("Setting NODE_ENV to 'production'" + "\n");
    process.env.NODE_ENV = 'production';
    if (process.env.NODE_ENV != 'production') {
        throw new Error("Failed to set NODE_ENV to production!");
    } else {
        process.stdout.write("Successfully set NODE_ENV to production" + "\n");
    }
});

gulp.task('build-css', function() {
    return gulp.src([
        'style.css',
        ])
        .pipe(sourcemaps.init())
        .pipe(cleanCSS({debug: true}))
        .pipe(concat('bundle.min.css'))
        .pipe(sourcemaps.write('./maps'))
        .pipe(gulp.dest('dist'))
        .pipe(livereload());
});
gulp.task('default', ['apply-prod-environment', 'build-css']);

Also, when I check the node version that I have installed:

$ node -v
The program 'node' is currently not installed. You can install it by typing:
sudo apt install nodejs-legacy

But:

$ nodejs --version
v4.7.2

Why? And it is an old version! How can I get the newer version?

npm seems OK:

$ npm -v
3.5.2

Any ideas?

I am on Ubuntu/ Kubuntu 17.04 btw.



via teelou

No comments:

Post a Comment