Answer the question
In order to leave comments, you need to log in
How to synchronize an asynchronous function?
Hello, I'm minifying css with css-nano, however it can only work in asynchronous mode.
An example of a minimize function using css-nano
const postcss = require("postcss");
const cssnano = require("cssnano");
const cssNanoPresetAdvanced = require("cssnano-preset-advanced");
let MINIFY_CSS = function (code) {
postcss(cssnano({ preset: cssNanoPresetAdvanced }))
.process(code)
.then(function (result) {
console.log(result.css);
});
},
MINIFY_CSS("html{background:green;}")
EXTRACT_CSS(MINIFY_CSS(require("!!raw-loader!sass-loader!./MyScss.scss")))
let MINIFY_CSS= function (code) {
let minified;
async () => {
await postcss(cssnano({ preset: cssNanoPresetAdvanced }))
.process(code)
.then(function (result) {
minified = result.css;
});
};
console.log(minified);
return minified;
},
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question