Gulp, PostCSS и UnCSS

Я пытаюсь очистить свой css и использовать UnCSS с gulp и Postcss.

У меня есть это:

gulp.task('optim-css', function() {
    var stream1 = gulp.src(['dev/css/bootstrap.min.css','dev/css/custom.css'])
        .pipe(postcss([ rucksack() ]))
        .pipe(postcss(uncss({
                html:   ['http://localhost/olssonseder/','http://localhost/olssonseder/lyssna/','http://localhost/olssonseder/repertoar/','http://localhost/olssonseder/kontakta/','http://localhost/olssonseder/kontakta/','http://localhost/olssonseder/om-gitarren/'],
                ignore: [new RegExp('.b-lazy*'),
                         new RegExp('.stickyFooter')]
            }))
        );

    var stream2 = gulp.src(['dev/css/responsive-nav.css','dev/css/lity.css','dev/css/mp3-player-button.css'])

    return merge(stream1, stream2)
        .pipe(concat('styles.css'))
        .pipe(cleanCSS())
        .pipe(gulp.dest(''))
        .pipe(browserSync.stream());
});

Но я получаю эту ошибку, и я просто не могу понять, почему:

[14:21:49] TypeError: UnCSS: expected a callback
    at init (C:\Users\Nicke\Documents\PortableApps\UwAmp\www\olssonseder\wp-content\themes\bastema\node_modules\uncss\src\uncss.js:176:15)
    at Gulp.<anonymous> (C:\Users\Nicke\Documents\PortableApps\UwAmp\www\olssonseder\wp-content\themes\bastema\gulpfile.js:48:23)
    at module.exports (C:\Users\Nicke\Documents\PortableApps\UwAmp\www\olssonseder\wp-content\themes\bastema\node_modules\orchestrator\lib\runTask.js:34:7)
    at Gulp.Orchestrator._runTask (C:\Users\Nicke\Documents\PortableApps\UwAmp\www\olssonseder\wp-content\themes\bastema\node_modules\orchestrator\index.js:273:3)
    at Gulp.Orchestrator._runStep (C:\Users\Nicke\Documents\PortableApps\UwAmp\www\olssonseder\wp-content\themes\bastema\node_modules\orchestrator\index.js:214:10)
    at Gulp.Orchestrator.start (C:\Users\Nicke\Documents\PortableApps\UwAmp\www\olssonseder\wp-content\themes\bastema\node_modules\orchestrator\index.js:134:8)
    at C:\Users\Nicke\Documents\PortableApps\UwAmp\www\olssonseder\wp-content\themes\bastema\node_modules\gulp\bin\gulp.js:129:20
    at process._tickCallback (internal/process/next_tick.js:150:11)
    at Function.Module.runMain (module.js:703:11)
    at startup (bootstrap_node.js:190:16)
[14:21:52] Finished 'optim-js' after 2.75 s
[14:21:52] Finished 'optim-deferjs' after 2.73 s
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] gi: `gulp init`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] gi 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\Nicke\AppData\Roaming\npm-cache\_logs\2018-07-27T12_21_52_508Z-debug.log

Кто-нибудь знает, почему это происходит?


person NiklasWideC    schedule 27.07.2018    source источник


Ответы (1)


Я столкнулся с той же проблемой. После создания обратного вызова и столкнувшись с другими проблемами, я обнаружил, что uncss нельзя использовать напрямую с postcss. Вместо этого используйте postcss-uncss, и он будет работать как положено.

Откуда: https://github.com/uncss/uncss

Примечание. В зависимости от вашей среды вы не сможете использовать uncss в качестве подключаемого модуля PostCSS, поскольку подключаемый модуль не экспортируется напрямую. В таких случаях используйте библиотеку-оболочку postcss-uncss.

Вот библиотека postcss-uncss: https://github.com/uncss/postcss-uncss

person Brian Lakstins    schedule 08.08.2018
comment
Привет! Спасибо за Ваш ответ. Я использую postcss-uncss. Я обнаружил, что мне нужно создавать статические html-файлы из моих страниц wordpress. Вместо localhost/website/mypage я использовал localhost/website/mypage/index.hml Странно... - person NiklasWideC; 10.08.2018