@apleasantview/eleventy-plugin-baseline 0.1.0-next.15 → 0.1.0-next.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -52,6 +52,19 @@ export default function assetsESBuild(eleventyConfig, options = {}) {
|
|
|
52
52
|
// Filter to inline a bundled entry.
|
|
53
53
|
eleventyConfig.addFilter("inlineESbuild", inlineESbuild);
|
|
54
54
|
|
|
55
|
+
// Filter to inline a bundled entry (async, works with callback or promise).
|
|
56
|
+
eleventyConfig.addAsyncFilter("inlineESbuild", async function (jsFilePath, callback) {
|
|
57
|
+
const done = typeof callback === "function" ? callback : null;
|
|
58
|
+
try {
|
|
59
|
+
const html = await inlineESbuild(jsFilePath);
|
|
60
|
+
if (done) return done(null, html);
|
|
61
|
+
return html;
|
|
62
|
+
} catch (error) {
|
|
63
|
+
if (done) return done(error);
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
55
68
|
// Override the default collection behavior. Adding js as template format and extension collects 11tydata.js files.
|
|
56
69
|
eleventyConfig.addCollection("all", function (collectionApi) {
|
|
57
70
|
return collectionApi.getAll().filter(item => {
|
|
@@ -3,6 +3,9 @@ import postcss from "postcss";
|
|
|
3
3
|
import loadPostCSSConfig from "postcss-load-config";
|
|
4
4
|
import fallbackPostCSSConfig from "../fallback/postcss.config.js";
|
|
5
5
|
|
|
6
|
+
// Resolve user PostCSS config from the project root (cwd), not the Eleventy input dir.
|
|
7
|
+
const configRoot = process.cwd();
|
|
8
|
+
|
|
6
9
|
export default async function inlinePostCSS(cssFilePath) {
|
|
7
10
|
try {
|
|
8
11
|
let cssContent = await fs.readFile(cssFilePath, 'utf8');
|
|
@@ -15,7 +18,9 @@ export default async function inlinePostCSS(cssFilePath) {
|
|
|
15
18
|
({ plugins, options } = await loadPostCSSConfig({}, configRoot));
|
|
16
19
|
} catch (error) {
|
|
17
20
|
// If none is found, fall back to the bundled Baseline config to keep builds working.
|
|
18
|
-
|
|
21
|
+
const { plugins: fallbackPlugins, ...fallbackOptions } = fallbackPostCSSConfig;
|
|
22
|
+
plugins = fallbackPlugins;
|
|
23
|
+
options = fallbackOptions;
|
|
19
24
|
}
|
|
20
25
|
|
|
21
26
|
let result = await postcss(plugins).process(cssContent, {
|
|
@@ -57,6 +57,16 @@ export default function assetsPostCSS(eleventyConfig) {
|
|
|
57
57
|
}
|
|
58
58
|
});
|
|
59
59
|
|
|
60
|
-
// Filter to inline a bundled entry.
|
|
61
|
-
eleventyConfig.
|
|
60
|
+
// Filter to inline a bundled entry; supports callback style (Nunjucks/Liquid) and Promise return.
|
|
61
|
+
eleventyConfig.addAsyncFilter("inlinePostCSS", async function (cssFilePath, callback) {
|
|
62
|
+
const done = typeof callback === "function" ? callback : null;
|
|
63
|
+
try {
|
|
64
|
+
const html = await inlinePostCSS(cssFilePath);
|
|
65
|
+
if (done) return done(null, html);
|
|
66
|
+
return html;
|
|
67
|
+
} catch (error) {
|
|
68
|
+
if (done) return done(error);
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
62
72
|
};
|
package/package.json
CHANGED