javascript - Gulpfile.js 请求

标签 javascript gulp gulp-sass

我正在尝试使用 autoprefixer、sass 和 livereload 运行一个 gulpfile。我花了一个晚上,但我无法运行它们,它到处爆炸 T.T

任何人都可以提供安装这些插件的教程或 gulpfile 吗?

非常感谢:D

gulp文件.js

'use strict';

var gulp = require('gulp'),
    sass = require('gulp-sass'),
    livereload = require('gulp-livereload'),
    autoprefixer = require('gulp-autoprefixer');

gulp.task('sass', function () {
    gulp.src('public_html/style/scss/**/*.scss')
        .pipe(sass().on('error', sass.logError))
        .pipe(autoprefixer({
            browsers: ['last 2 versions'],
            cascade: false
        }))
        .pipe(gulp.dest('css'))
        .pipe(livereload());
});

gulp.task('watch', function () {
    livereload.listen(35729);
    gulp.watch('public_html/style/scss/**/*.scss', ['sass']);
});

来自终端的错误日志:

[22:46:02] Using gulpfile /var/www/satbalma/Gulpfile.js
[22:46:02] Starting 'watch'...
[22:46:03] Finished 'watch' after 357 ms
[22:48:43] Starting 'sass'...
[22:48:43] Finished 'sass' after 22 ms

/var/www/satbalma/node_modules/gulp-autoprefixer/node_modules/postcss/lib/lazy-result.js:157
    this.processing = new Promise(function (resolve, reject) {
                          ^
ReferenceError: Promise is not defined
at LazyResult.async (/var/www/satbalma/node_modules/gulp-autoprefixer/node_modules/postcss/lib/lazy-result.js:157:31)
at LazyResult.then (/var/www/satbalma/node_modules/gulp-autoprefixer/node_modules/postcss/lib/lazy-result.js:79:21)
at DestroyableTransform._transform (/var/www/satbalma/node_modules/gulp-autoprefixer/index.js:24:6)
at DestroyableTransform.Transform._read (/var/www/satbalma/node_modules/gulp-autoprefixer/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:159:10)
at DestroyableTransform.Transform._write (/var/www/satbalma/node_modules/gulp-autoprefixer/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:147:83)
at doWrite (/var/www/satbalma/node_modules/gulp-autoprefixer/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:313:64)
at writeOrBuffer (/var/www/satbalma/node_modules/gulp-autoprefixer/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:302:5)
at DestroyableTransform.Writable.write (/var/www/satbalma/node_modules/gulp-autoprefixer/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:241:11)
at DestroyableTransform.ondata (/var/www/satbalma/node_modules/gulp-sass/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:531:20)
at DestroyableTransform.emit (events.js:95:17)

最佳答案

我之前有过这个错误。 将以下内容添加到您的 package.json

"es6-promise": "~3.1.2",
"es6-promise-polyfill": "~1.2.0",

并在您的 gulpfile.js 中执行:

var Promise      = require('es6-promise').Promise;

应该有帮助

关于javascript - Gulpfile.js 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36508380/

相关文章:

javascript - 弹出表单成功消息

gulp - 将我的 scss 文件吞入 css 文件后,如何防止 gulp-sass 创建文件夹 "sass"?

javascript - 如果 div 的名称不是容器,Jquery 上下文菜单插件将停止工作?

javascript - 是否可以更改轴标签的颜色并将其格式化为 jsxgraph?

javascript - 这个javascript是什么意思

node.js - 将 npm script 命令行参数传递给其中的特定脚本

javascript - Gulp.js,保存文件时观察任务运行两次

javascript - 使用 Gulp Header 在 Header 文件中包含当前年份

javascript - 为什么我的 Sass 在使用 Gulp 时没有出现?

javascript - Gulp sass 编译在启动时正常工作。但是,更改的文件将被排除