1
Выдает ошибку:
"C:\Program Files\nodejs\node.exe" "C:\Program 
Files\nodejs\node_modules\npm\bin\npm-cli.js" run dev --scripts-prepend- 
node-path=auto

> tour@1.0.0 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! tour@1.0.0 dev: `gulp watch --dev --sync`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the tour@1.0.0 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

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);
{
 "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"
    }
   }

1 ответ 1

0
function watch(){
if(isSync){
    browserSync.init({
        server: {
            baseDir: "./build/",
        }
    });
}
gulp.watch('./src/js/**/*.js', js);
gulp.watch('./src/fonts/**/*', fonts);
gulp.watch('./src/css/**/*.less', styles);
gulp.watch('./src/**/*.html', html);
gulp.watch('./smartgrid.js', grid);
}
function js(){
   return gulp.src('./src/js/*.js')
    .pipe(concat('main.min.js'))
    .pipe(babel({
        presets: ['@babel/env']
    }))
    .pipe(uglify()) // Минифицирует js
    .pipe(gulp.dest('build/js'))
    .pipe(browserSync.reload({stream: true}));
   }

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.