我正在尝试在Docksal容器中运行Addy Osmani的吞噬关键任务,并且使错误超出我的知识库。
var config = {
critical: {
width: 1280,
height: 900,
dest: 'critical-css/',
urls: {
'/': 'home',
'/test-page': 'page',
'/test-place': 'location'
}
}
};
var configLocal = {
critical: {
baseDomain: 'http://sitename.docksal/'
}
};
// Allow requests to work with non-valid SSL certificates.
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
// gulp.task('critical', ['critical:clean'], function (done) {
gulp.task('critical', function (done) {
Object.keys(config.critical.urls).map(function(url, index) {
var pageUrl = urljoin( configLocal.critical.baseDomain, url );
var destCssPath = path.join(process.cwd(), config.critical.dest, config.critical.urls[url] + '.css' );
return rp({uri: pageUrl, strictSSL: false}).then(function (body) {
var htmlString = body
.replace(/href="\//g, 'href="' + urljoin(configLocal.critical.baseDomain, '/'))
.replace(/src="\//g, 'src="' + urljoin(configLocal.critical.baseDomain, '/'));
//gutil.log('Generating critical css', gutil.colors.magenta(destCssPath), 'from', pageUrl);
critical.generate({
base: osTmpdir(),
html: htmlString,
src: '',
dest: destCssPath,
minify: true,
width: config.critical.width,
height: config.critical.height
});
if (index+1 === Object.keys(config.critical.urls).length) {
return done();
}
});
});
});
完成任务时,出现以下错误:
(节点:1766)UnhandledPromiseRejection警告:错误:无法启动chrome! /var/www/docroot/themes/custom/sitename/node_modules/puppeteer/.local-chromium/linux-594312/chrome-linux/chrome:加载共享库时出错:libX11-xcb.so.1:无法打开共享库文件:没有这样的文件或目录
故障排除:https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md
该链接说我需要添加到我的docker文件中。那是Docksal的docker文件吗?还是项目中的某处?
启动无头的Chrome并在Docker中运行可能很棘手。 Puppeteer安装的捆绑的Chromium缺少必需的共享库依赖项。
要修复,您需要在Dockerfile中安装缺少的依赖项和最新的Chromium软件包...