E
E
Evgen Roev2019-10-02 21:22:19
gulp.js
Evgen Roev, 2019-10-02 21:22:19

Gulp build not working?

Gives an error message:

"C:\Program Files\nodejs\node.exe" "C:\Program 
    Files\nodejs\node_modules\npm\bin\npm-cli.js" run dev --scripts-prepend- 
    node-path=auto

    > [email protected] dev C:\frontend\verstka\granit
    > gulp watch --dev --sync

    [20:45:33] Using gulpfile C:\frontend\verstka\granit\gulpfile.js
    [20:45:33] Starting 'watch'...
    [20:45:33] Starting 'clear'...
    [20:45:33] Finished 'clear' after 42 ms
    [20:45:33] Starting 'styles'...
    [20:45:33] Starting 'img'...
    [20:45:33] Starting 'html'...
    [20:45:33] Starting 'js'...
    [20:45:33] Starting 'fonts'...
    [20:45:33] 'js' errored after 234 ms
    [20:45:33] GulpUglifyError: unable to minify JavaScript
    Caused by: SyntaxError: Unexpected line terminator
    File: C:\frontend\verstka\granit\src\js\main.min.js
    Line: 1
    [20:45:33] 'watch' errored after 297 ms
    [20:45:33] The following tasks did not complete: styles, img, html, fonts
    [20:45:33] Did you forget to signal async completion?
    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! [email protected] dev: `gulp watch --dev --sync`
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the [email protected] dev script.
    npm ERR! This is probably not a problem with npm. There is likely additional 
     logging output above.

     npm ERR! A complete log of this run can be found in:
     npm ERR!     C:\Users\Admin\AppData\Roaming\npm-cache\_logs\2019-10- 
     02T17_45_33_624Z-debug.log

     Process finished with exit code 1

My gulpfile.js:
const gulp = require('gulp');
const autoprefixer = require('gulp-autoprefixer');
const del = require('del');
const browserSync = require('browser-sync').create();
const concat = require('gulp-concat');
const uglify  = require('gulp-uglify');
const cleanCSS = require('gulp-clean-css');
const sourcemaps = require('gulp-sourcemaps');
const gulpif = require('gulp-if');
const gcmq = require('gulp-group-css-media-queries');
const less = require('gulp-less');
const smartgrid = require('smart-grid');

const isDev = (process.argv.indexOf('--dev') !== -1);
const isProd = !isDev;
const isSync = (process.argv.indexOf('--sync') !== -1);


function clear(){
  return del('build/*');
}

function styles(){
  return gulp.src('./src/css/+(styles|styles-per|styles-ie9).less')
    .pipe(gulpif(isDev, sourcemaps.init()))
    .pipe(less())
    //.pipe(concat('style.css'))
    .pipe(gcmq())
    .pipe(autoprefixer({
      browsers: ['> 0.1%'],
      cascade: false
    }))
    //.on('error', console.error.bind(console))
    .pipe(gulpif(isProd, cleanCSS({
      level: 2
    })))
    .pipe(gulpif(isDev, sourcemaps.write()))
    .pipe(gulp.dest('./build/css'))
    .pipe(gulpif(isSync, browserSync.stream()));
}

function img(){
  return gulp.src('./src/img/**/*')
    .pipe(gulp.dest('./build/img'))
}
function fonts(){
  return gulp.src('./src/fonts/**/*')
    .pipe(gulp.dest('./build/fonts'))
}

function js(){
  return gulp.src('./src/js/*.js')
    .pipe(concat('main.min.js'))
    .pipe(uglify()) // Минифицирует js
    .pipe(gulp.dest('build/js'))
    .pipe(browserSync.reload({stream: true}));
}

function html(){
  return gulp.src('./src/*.html')
    .pipe(gulp.dest('./build'))
    .pipe(gulpif(isSync, browserSync.stream()));
}

function watch(){
  if(isSync){
    browserSync.init({
      server: {
        baseDir: "./build/",
      }
    });
  }
  gulp.watch('./src/fonts/**/*.js', fonts);
  gulp.watch('./src/js/**/*.js', js);
  gulp.watch('./src/css/**/*.less', styles);
  gulp.watch('./src/**/*.html', html);
  gulp.watch('./smartgrid.js', grid);
}

function grid(done){
  delete require.cache[require.resolve('./smartgrid.js')];

  let settings = require('./smartgrid.js');
  smartgrid('./src/css', settings);

  settings.offset = '3.1%';
  settings.filename = 'smart-grid-per';
  smartgrid('./src/css', settings);

  done();
}

let build = gulp.series(clear,
  gulp.parallel(styles, img, html,js,fonts)
);

gulp.task('build', gulp.series(grid, build));
gulp.task('watch', gulp.series(build, watch));
gulp.task('grid', grid);

My package.json:
{
  "name": "granit",
  "version": "1.0.0",
  "description": "",
  "main": "gulpfile.js",
  "scripts": {
    "dev": "gulp watch --dev --sync",
    "build": "gulp build"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "normalize.css": "^8.0.1"
  },
  "devDependencies": {
    "browser-sync": "^2.26.7",
    "del": "^5.1.0",
    "gulp": "^4.0.2",
    "gulp-autoprefixer": "^7.0.0",
    "gulp-clean-css": "^4.2.0",
    "gulp-concat": "^2.6.1",
    "gulp-group-css-media-queries": "^1.2.2",
    "gulp-if": "^3.0.0",
    "gulp-less": "^4.0.1",
    "gulp-sourcemaps": "^2.6.5",
    "gulp-uglify": "^3.0.2",
    "smart-grid": "^2.1.2"
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgen Roev, 2019-10-03
@roevevgen

Everything fixed
My gulpfile.js:

const gulp = require('gulp');
const autoprefixer = require('gulp-autoprefixer');
const del = require('del');
const browserSync = require('browser-sync').create();
const concat = require('gulp-concat');
const babel = require('gulp-babel');
const uglify  = require('gulp-uglify');
const cleanCSS = require('gulp-clean-css');
const sourcemaps = require('gulp-sourcemaps');
const gulpif = require('gulp-if');
const gcmq = require('gulp-group-css-media-queries');
const less = require('gulp-less');
const smartgrid = require('smart-grid');

const isDev = (process.argv.indexOf('--dev') !== -1);
const isProd = !isDev;
const isSync = (process.argv.indexOf('--sync') !== -1);



function clear(){
  return del('build/*');
}

function styles(){
  return gulp.src('./src/style/+(styles|styles-per|styles-ie9).less')
         .pipe(gulpif(isDev, sourcemaps.init()))
         .pipe(less())
         //.pipe(concat('style.css'))
         .pipe(gcmq())
         .pipe(autoprefixer({
                browsers: ['> 0.1%'],
                cascade: false
            }))
         //.on('error', console.error.bind(console))
         .pipe(gulpif(isProd, cleanCSS({
         		level: 2
         })))
         .pipe(gulpif(isDev, sourcemaps.write()))
         .pipe(gulp.dest('./build/css'))
         .pipe(gulpif(isSync, browserSync.stream()));
}

function img(){
  return gulp.src('./src/img/**/*')
         .pipe(gulp.dest('./build/img'))
}

function js(){
  return gulp.src('./src/js/*.js')
    .pipe(concat('main.min.js'))
    .pipe(babel({
      presets: ['@babel/env']
    }))
    .pipe(uglify())
    .pipe(gulp.dest('build/js'))
    .pipe(browserSync.reload({stream: true}));
}
function fonts(){
  return gulp.src('./src/fonts/**/*')
    .pipe(gulp.dest('./build/fonts'))
}

function html(){
  return gulp.src('./src/*.html')
         .pipe(gulp.dest('./build'))
         .pipe(gulpif(isSync, browserSync.stream()));
}

function watch(){
  if(isSync){
    browserSync.init({
          server: {
              baseDir: "./build/",
          }
      });
  }
  gulp.watch('./src/js/**/*.js', js);
  gulp.watch('./src/fonts/**/*', fonts);
  gulp.watch('./src/style/**/*.less', styles);
  gulp.watch('./src/**/*.html', html);
  gulp.watch('./smartgrid.js', grid);
}

function grid(done){
  delete require.cache[require.resolve('./smartgrid.js')];

  let settings = require('./smartgrid.js');
  smartgrid('./src/style', settings);

  settings.offset = '3.1%';
  settings.filename = 'smart-grid-per';
  smartgrid('./src/style', settings);

  done();
}

let build = gulp.series(clear, 
  gulp.parallel(styles, img, html,fonts,js)
);

gulp.task('build', gulp.series(grid, build));
gulp.task('watch', gulp.series(build, watch));
gulp.task('grid', grid);

My package.json:
{
  "name": "granit",
  "version": "1.0.0",
  "description": "",
  "main": "gulpfile.js",
  "scripts": {
    "dev": "gulp watch --dev --sync",
    "build": "gulp build"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "normalize.css": "^8.0.1"
  },
  "devDependencies": {
    "@babel/core": "^7.6.2",
    "@babel/preset-env": "^7.6.2",
    "browser-sync": "^2.26.7",
    "del": "^5.1.0",
    "gulp": "^4.0.2",
    "gulp-autoprefixer": "^7.0.0",
    "gulp-babel": "^8.0.0",
    "gulp-clean-css": "^4.2.0",
    "gulp-concat": "^2.6.1",
    "gulp-group-css-media-queries": "^1.2.2",
    "gulp-if": "^3.0.0",
    "gulp-less": "^4.0.1",
    "gulp-sourcemaps": "^2.6.5",
    "gulp-uglify": "^3.0.2",
    "smart-grid": "^2.1.2"
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question