Gulp任务不起作用?

时间:2016-07-10 20:59:17

标签: node.js npm gulp

嘿所以我有一个gulp任务来缩小我的html文件,但它不起作用。

gulpfile.js内容:

var gulp = require('gulp');
var autoprefixer = require('gulp-autoprefixer');
var htmlmin = require('gulp-html-minifier');



gulp.task('autoprefixer', function () {
    return gulp.src('assets/css/*.css')
        .pipe(autoprefixer({
            browsers: ['last 2 versions'],
            cascade: false
        }))
        .pipe(gulp.dest('../../dist/css/'));
});

gulp.task('minify-html', function() {
  gulp.src('*.html')
    .pipe(htmlmin({collapseWhitespace: true}))
    .pipe(gulp.dest('dist/'))
});

输出:

C:\ Users \ Jack \ Desktop \ Zoid Studios \ node_modules \ map-stream \ index.js:103 throw err ^错误:解析错误:Zoid Studios - Web Agency在新的HTMLParser(C:\ Users \ Jack \ Desktop \ Zoid Studios \ node_modules \ gulp -html-minifier \ node_modules \ html-minifier \ src \ htmlparser.js:236:13)
                                                                                                    at minify(C:\ Users \ Jack \ Desktop \ Zoid Studios \ node_modules \ gulp -html-minifier \ node_modules \ html-minifier \ src \ htmlminifier.js:861:3)                                                                                                             at Object.exports.minify(C:\ Users \ Jack \ Desktop \ Zoid Studios \ node_modules \ gulp -html-minifier \ node_modules \ html-minifier \ src \ htmlminifier.js:1216:10)                                                                                            在C:\ Users \ Jack \ Desktop \ Zoid Studios \ node_modules \ gulp-html-minifier \ index.js:51:40

在wrappedMapper(C:\ Users \ Jack \ Desktop \ Zoid Studios \ node_modules \ map-stream \ index.js:84:19)

在Stream.stream.write(C:\ Users \ Jack \ Desktop \ Zoid Studios \ node_modules \ map-stream \ index.js:96:21)

at write(C:\ Users \ Jack \ Desktop \ Zoid Studios \ node_modules \ vinyl-fs \ node_modules \ readable-stream \ lib_stream_readable.js:623:24)                                                                                                                  at flow(C:\ Users \ Jack \ Desktop \ Zoid Studios \ node_modules \ vinyl-fs \ node_modules \ readable-stream \ lib_stream_readable.js:632:7)                                                                                                                    在DestroyableTransform.pipeOnReadable(C:\ Users \ Jack \ Desktop \ Zoid Studios \ node_modules \ vinyl-fs \ node_modules \ readable-stream \ lib_stream_readable.js:664:5)                                                                                    在emitNone(events.js:67:13)C:\ Users \ Jack \ Desktop \ Zoid Studios>

我使用" gulp minify-html"命令在npm cmd提示符下。

任何帮助?

1 个答案:

答案 0 :(得分:1)

我的项目正在使用此代码。请注意,该任务正在根目录中查看我的src文件夹。并且输出将写入我的根目录中的dist文件夹。

我已经安装了手表插件:npm install --save-dev gulp-watch和html min:npm i gulp-htmlmin --save-dev

var gulp = require('gulp');
var htmlmin = require('gulp-htmlmin');
var watch = require('gulp-watch');

gulp.task('default', ['watch','minify']);

gulp.task('watch', function() {
    gulp.watch('src/*.html', ['minify']);
});

gulp.task('minify', function() {
  return gulp.src('src/*.html')
    .pipe(htmlmin({collapseWhitespace: true}))
    .pipe(gulp.dest('dist'))
});