运行gulp-uncss时出现问题,以摆脱所有未使用的代码。 这个错误似乎与解析css有关。
C:\wamp64\www\css-cleanup\node_modules\gulp-uncss\node_modules\uncss\node_modules\bluebird\js\release\async.js:48
fn = function () { throw arg; };
^
Error: uncss/node_modules/css: unable to parse undefined:
missing '{' near line 34:1
29: @import "components/_navbar";
30: @import "components/_slick";
31: @import "components/_slick-theme";
32: @import "components/_slack";
33: //@import "components/_landing";
34: ->
at error (C:\wamp64\www\css-cleanup\node_modules\gulp-uncss\node_modules\uncss\node_modules\css\node_modules\css-parse\index.js:57:15)
at declarations (C:\wamp64\www\css-cleanup\node_modules\gulp-uncss\node_modules\uncss\node_modules\css\node_modules\css-parse\index.js:214:25)
at rule (C:\wamp64\www\css-cleanup\node_modules\gulp-uncss\node_modules\uncss\node_modules\css\node_modules\css-parse\index.js:481:21)
at rules (C:\wamp64\www\css-cleanup\node_modules\gulp-uncss\node_modules\uncss\node_modules\css\node_modules\css-parse\index.js:103:56)
at stylesheet (C:\wamp64\www\css-cleanup\node_modules\gulp-uncss\node_modules\uncss\node_modules\css\node_modules\css-parse\index.js:73:16)
at Object.module.exports [as parse] (C:\wamp64\www\css-cleanup\node_modules\gulp-uncss\node_modules\uncss\node_modules\css\node_modules\css-parse\index.js:485:10)
at process (C:\wamp64\www\css-cleanup\node_modules\gulp-uncss\node_modules\uncss\src\uncss.js:158:22)
at tryCatcher (C:\wamp64\www\css-cleanup\node_modules\gulp-uncss\node_modules\uncss\node_modules\bluebird\js\release\util.js:11:23)
at Promise._settlePromiseFromHandler (C:\wamp64\www\css-cleanup\node_modules\gulp-uncss\node_modules\uncss\node_modules\bluebird\js\release\promise.js:488:35)
at Promise._settlePromise (C:\wamp64\www\css-cleanup\node_modules\gulp-uncss\node_modules\uncss\node_modules\bluebird\js\release\promise.js:548:18)
at Promise._settlePromise0 (C:\wamp64\www\css-cleanup\node_modules\gulp-uncss\node_modules\uncss\node_modules\bluebird\js\release\promise.js:593:10)
at Promise._settlePromises (C:\wamp64\www\css-cleanup\node_modules\gulp-uncss\node_modules\uncss\node_modules\bluebird\js\release\promise.js:676:18)
at Promise._fulfill (C:\wamp64\www\css-cleanup\node_modules\gulp-uncss\node_modules\uncss\node_modules\bluebird\js\release\promise.js:617:18)
at PromiseArray._resolve (C:\wamp64\www\css-cleanup\node_modules\gulp-uncss\node_modules\uncss\node_modules\bluebird\js\release\promise_array.js:125:19)
at PromiseArray._promiseFulfilled (C:\wamp64\www\css-cleanup\node_modules\gulp-uncss\node_modules\uncss\node_modules\bluebird\js\release\promise_array.js:143:14)
at Promise._settlePromise (C:\wamp64\www\css-cleanup\node_modules\gulp-uncss\node_modules\uncss\node_modules\bluebird\js\release\promise.js:553:26)
我的gulpfile.js看起来像这样:
var gulp = require('gulp');
var uncss = require('gulp-uncss');
gulp.task('default', function () {
return gulp.src('sass/**/*.scss')
.pipe(uncss({
html: ['index.html']
}))
.pipe(gulp.dest('./css_new/'));
});