使用gulp使用gulp-autoprefixer的问题

问题描述 投票:0回答:1

您能否建议如何解决以下错误?一切正常,但是当我尝试添加gulp-autoprefixer时,终端出现gulp出现此错误。希望对您有所帮助。

node -vv6.10.3

npm -v3.10.10

gulp -vCLI版本:2.2.0本地版本:3.9.1

enter image description here

package.json文件

{
  "name": "igor",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "browser-sync": "^2.14.0",
    "gulp": "^3.9.1",
    "gulp-autoprefixer": "^7.0.0",
    "gulp-concat": "^2.6.0",
    "gulp-rename": "^1.2.2",
    "gulp-ruby-sass": "^2.1.0",
    "gulp-sourcemaps": "^1.6.0",
    "postcss-loader": "^3.0.0"
  }
}

gulpfile.js文件

var gulp = require('gulp');
var concat = require('gulp-concat');
var browserSync = require('browser-sync');
var sass = require('gulp-ruby-sass');
var rename = require('gulp-rename');
var sourcemaps = require('gulp-sourcemaps');
var autoprefixer = require('gulp-autoprefixer');


var Files = {
  html: './index.html',
  css_dest: './css',
  scss: './scss/style.scss',
  js_dest: './js',
  js: './js/app.js'
};

gulp.task('sass', function () {
  return sass(Files.scss, {
      style: 'expanded',
      sourcemap: true
    })
    .on('error', sass.logError)
    .pipe(sourcemaps.write())
    .pipe(autoprefixer({
      browsers: ['last 2 versions'],
      cascade: false
    }))
    .pipe(rename('main.css'))
    .pipe(gulp.dest(Files.css_dest))
    .pipe(browserSync.reload({
      stream: true
    }));
});


gulp.task('js', function () {
  return gulp.src(Files.js)
    .pipe(concat('main.js'))
    .pipe(gulp.dest(Files.js_dest))
    .pipe(browserSync.reload({
      stream: true
    }));
});


gulp.task('default', ['sass', 'js'], function () {
  browserSync.init({
    server: {
      baseDir: "./"
    }
  });

  gulp.watch('./scss/**/*.scss', ['sass']);
  gulp.watch('./js/**/*.js', ['js']);
  gulp.watch(Files.html, browserSync.reload);
});
sass gulp
1个回答
0
投票

您使用的gulp-autoprefixer版本至少需要节点8。您正在运行节点6,该节点不识别或不支持某些较新的Javascript语法。您可以将gulp-autoprefixer降级为6.10.0,或者如果可能的话,升级到Node> = 8。

© www.soinside.com 2019 - 2024. All rights reserved.