Skip to content

Commit fe5a2a4

Browse files
authored
feat: Make mixManifest optional (#36)
1 parent 96d0b21 commit fe5a2a4

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ As mentioned in the `eleventyConfig.addPlugin(eleventy-plugin-twig, USER_OPTIONS
9797

9898
/**
9999
* @typedef {object} USER_OPTIONS
100-
* @property {string} mixManifest - path to the mixManifest file relative to the build folder
100+
* @property {string} [mixManifest] - path to the mixManifest file relative to the build folder
101101
* @property {ASSETS} [assets] - where to find all the assets relative to the build folder
102102
* @property {IMAGES} [images] - options for Eleventys image processing
103103
* @property {ELEVENTY_DIRECTORIES} dir - Eleventy folder decisions

lib/plugin.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,18 @@ const handleErrors = (userOptions) => {
6767
);
6868
}
6969

70-
if (!userOptions.mixManifest) {
71-
errors.push("userOptions.mixManifest is not defined.");
72-
}
73-
74-
if (!userOptions.mixManifest?.match(/^[\w-_]+.json$/)) {
75-
errors.push(
76-
"userOptions.mixManifest does not provide a valid filename (for example 'foobar.json')."
77-
);
78-
}
79-
80-
if (userOptions.mixManifest && !userOptions.assets?.base) {
81-
errors.push(
82-
"userOptions.mixManifest requires userOptions.assets.base to be defined."
83-
);
70+
if (userOptions.mixManifest) {
71+
if (!userOptions.mixManifest.match(/^[\w-_]+.json$/)) {
72+
errors.push(
73+
"userOptions.mixManifest does not provide a valid filename (for example 'foobar.json')."
74+
);
75+
}
76+
77+
if (!userOptions.assets?.base) {
78+
errors.push(
79+
"userOptions.mixManifest requires userOptions.assets.base to be defined."
80+
);
81+
}
8482
}
8583

8684
if (!userOptions.dir) {

lib/shortcodes/mix.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const fs = require("fs");
1010
* @returns {string}
1111
*/
1212
module.exports = (eleventyConfig, userOptions, originalAsset) => {
13+
if (!userOptions.mixManifest) return originalAsset;
14+
1315
const mix = JSON.parse(
1416
fs.readFileSync(
1517
`./${userOptions.dir.output}/${userOptions.mixManifest}`,

0 commit comments

Comments
 (0)