Open schellenbergk opened 5 years ago
This addition would be fantastic.
Hey @schellenbergk, does your build task quit ok and show the ✨ Done in Xs
message once it's finished? Mine doesn't unless I remove...
const critical = require('critical');
...from my task-config.js
file (which I obviously need!), while all the tasks run as expected, once I see the message Finished 'build' after 11 s
the task doesn't quit and I have to manually CTRL + C
and I've no idea why.
I see this issue even without your suggested additions to the main package. Any ideas?
Hi @mikeebee , Yes mine does exit with Done in Xs
. Remember for this to work you would need to modify productionTask
and move postbuild
after 'replaceFiles'
task. However, unless this feature gets implemented I've made a workaround outside of Blendid:
Create a file criticalCss.js
with:
const critical = require('critical');
const fs = require('file-system');
const path = require('path');
const loadJsonFile = require('load-json-file');
const projectDestPath = path.resolve(process.env.PWD, 'public/');
const revManifestPath = path.resolve(projectDestPath, 'rev-manifest.json');
console.log('Critical CSS...');
fs.copyFile('public/index.html', 'public/index-uncritical.html', {
done: function (err) {
loadJsonFile(revManifestPath).then(json => {
critical.generate({
base: projectDestPath,
src: 'index.html',
width: 1300,
height: 900,
inline: true,
target: {
html: path.resolve(projectDestPath, 'index.html'),
uncritical: path.resolve(projectDestPath, json['css/app.css'].replace('.css', '-uncritical.css'))
},
minify: true,
extract: true,
});
console.log("Complete!");
});
}
});
Then modify your package.json
and update build
script to:
"scripts": {
"start": "yarn run blendid",
"build": "yarn run blendid build && node criticalCss.js",
...
Hi @schellenbergk, ah yes this works perfectly!
I wish I knew why the task won't quit when I'm using additionalTasks
with critical
. For my purposes, running a task on production.postbuild
would be fine. I'll stick with your implementation for the time being, it's a better solution anyway, I just hate not knowing what the issue is.
Thanks again for your help, I would have been stuck otherwise!
I'm glad I could help :)
I've written an
additionTask
forcritical css
:however
production.postbuild
executes beforereplaceFiles
task therefore it will never have access torev-manifest.json
: (productionTask)At this time, I can only get my
criticalCss
task to work only if I updateproductionTask
to:Perhaps we could add another hook for this kind of case, something like: