Refactor postcss.js

Decoupled import routine from final export to provide a shared instance of the PostCSS processor and for easier readability of file.
This commit is contained in:
Chauncey McAskill
2021-09-16 18:01:16 -04:00
parent ffece71aac
commit 834c6165b0

View File

@@ -1,19 +1,14 @@
/**
* If available, create the PostCSS processor with any plugins.
*
* @type {?module:postcss~Processor}
* @file If available, returns the PostCSS processor with any plugins.
*/
export default await (async () => {
try {
const { default: postcss } = await import('postcss');
const { default: autoprefixer } = await import('autoprefixer');
if (postcss && autoprefixer) {
return postcss([ autoprefixer ]);
}
} catch (err) {
// swallow this error; postcss and plugins are optional.
}
try {
var { default: postcss } = await import('postcss');
let { default: autoprefixer } = await import('autoprefixer');
return null;
})();
postcss = postcss([ autoprefixer ]);
} catch (err) {
postcss = null;
}
export default postcss;